alltools.one
Web Developmentβ€’
2026-02-12
β€’
7 min
β€’
alltools.one Team
urlencodingweb-developmenthttpapi

URL Encoding Guide: Why and How to Encode URLs

Ever wonder why spaces in URLs become %20 and ampersands become %26? URL encoding (also called percent-encoding) converts characters that are not safe for URLs into a format that web servers can understand.

Why URL Encoding Matters

URLs can only contain a limited set of ASCII characters. Special characters, spaces, and non-ASCII text need encoding to be transmitted safely. Without encoding, URLs break in unpredictable ways β€” a space could truncate a URL, an ampersand could be mistaken for a parameter separator.

Try our URL Encoder/Decoder to see how any text transforms when encoded for URLs.

Which Characters Need Encoding?

Safe Characters (no encoding needed)

Letters (A-Z, a-z), digits (0-9), and these symbols: -, _, ., ~

Reserved Characters (encode when used as data)

CharacterEncodedPurpose in URLs
:%3AScheme separator
/%2FPath separator
?%3FQuery string start
#%23Fragment identifier
&%26Parameter separator
=%3DKey-value separator
+%2BOften represents space
@%40User info separator
%%25Encoding indicator

Always Encode

Spaces (%20), non-ASCII characters (UTF-8 bytes encoded), and any character outside the safe set.

URL Encoding in Practice

Query Parameters

The most common use case. When building search URLs or API requests:

https://api.example.com/search?q=hello%20world&lang=en

Form Data

HTML forms with method="GET" URL-encode field values automatically. Spaces become + in form encoding (slightly different from percent-encoding).

Path Segments

File names and resource identifiers in URL paths need encoding too. A file named my report.pdf becomes my%20report.pdf in the URL.

Encoding in Different Languages

JavaScript:

encodeURIComponent('hello world & more')
// "hello%20world%20%26%20more"

decodeURIComponent('hello%20world')
// "hello world"

Python:

from urllib.parse import quote, unquote
quote('hello world & more')
# 'hello%20world%20%26%20more'

Common Mistakes

  1. Double encoding β€” Encoding an already-encoded URL turns %20 into %2520
  2. Using encodeURI instead of encodeURIComponent β€” encodeURI skips reserved characters that matter in query values
  3. Not encoding + signs β€” In URLs, + can mean space. Encode literal plus signs as %2B
  4. Forgetting non-ASCII β€” Unicode characters need UTF-8 encoding first, then percent-encoding

Frequently Asked Questions

What is the difference between encodeURI and encodeURIComponent?

encodeURI encodes a complete URL, skipping characters like :, /, ?, #. encodeURIComponent encodes everything except unreserved characters β€” use it for individual query parameter values.

Why do spaces sometimes become + and sometimes %20?

Form encoding (application/x-www-form-urlencoded) uses + for spaces. Standard percent-encoding uses %20. Both are valid in different contexts.

Related Resources

Published on 2026-02-12
URL Encoding Guide: Why and How to Encode URLs | alltools.one