In this article
Why URLs need encoding
Web addresses may only contain a limited set of characters. Some characters have special jobs: “?” starts the query, “&” separates parameters, “#” starts a fragment, “/” separates path parts. If your data contains those characters, or spaces, accents or non-Latin letters, it must be encoded so it is not mistaken for structure. Each byte is written as “%” plus two hexadecimal digits: a space becomes %20, “&” becomes %26.
Common encodings
| Character | Encoded |
|---|---|
| space | %20 (or + in form data) |
| & | %26 |
| ? | %3F |
| # | %23 |
| / | %2F |
| é | %C3%A9 |
| ا (Urdu alif) | %D8%A7 |
Non-English letters become several % codes because they are encoded as UTF-8 bytes first.
Component vs full URL
This is where most mistakes happen. There are two modes, the same as JavaScript’s two functions:
- Component mode (
encodeURIComponent) encodes everything special, including “/”, “?” and “&”. Use it for a single value you are putting into a URL, a search term, a name, a redirect address. - Full-URL mode (
encodeURI) leaves the structural characters alone and encodes only what is not allowed. Use it to clean up a whole address that contains spaces or accents.
Encoding a value with full-URL mode leaves “&” unencoded, so q=salt & pepper silently becomes two parameters. Encoding a whole URL with component mode turns “https://” into “https%3A%2F%2F”, which no longer works as a link.
How to encode
- Open the URL Encoder.
- Choose component or full-URL mode.
- Optionally use “+” for spaces, the style used by HTML forms in query strings.
- Type or paste, the output updates as you type.
Building a link with a search term
Suppose you want a link that searches a site for “shoes & bags”. Encode just the term in component mode: shoes%20%26%20bags. Then build the link: https://shop.com/search?q=shoes%20%26%20bags. For marketing links with several parameters, the UTM Builder handles all of the encoding for you.
Encoding in spreadsheets and code
If you build links in bulk, most environments have a built-in function: Excel’s ENCODEURL(), Google Sheets’ ENCODEURL(), JavaScript’s encodeURIComponent(), Python’s urllib.parse.quote() and PHP’s rawurlencode(). Use this tool to check a few results by hand when something looks wrong.
Do not encode twice
Encoding an already-encoded string turns “%20” into “%2520” (the % itself gets encoded). If you see “%25” in a link, something was encoded twice. Decode it with the URL Decoder and encode once.
URL encoding vs other encodings
URL encoding is for addresses. For embedding text in HTML, use the HTML Entity Encoder; for turning binary data into text, use Base64. To see each part of a complex address, use the URL Parser.
Common characters and their codes
These are the characters you meet most often in links. The URL Encoder converts any text for you.
| Character | Encoded | Why it needs encoding |
|---|---|---|
| space | %20 | Spaces are not allowed in a URL |
| & | %26 | Separates query parameters |
| = | %3D | Separates a name from its value |
| ? | %3F | Starts the query string |
| # | %23 | Starts a page fragment |
| + | %2B | Often read as a space in forms |
| , | %2C | Can confuse some systems |
| @ | %40 | Has a special meaning before the host name |
| % | %25 | Starts every encoded character |
Real examples
- A search for
salt & pepperbecomesq=salt%20%26%20pepper. Without encoding, the site would think "pepper" was a separate parameter. - A price filter
a+bmust be sent asa%2Bb, or the server may read it as "a b". - Non English letters are encoded byte by byte. The Urdu letter پ becomes
%D9%BE, which is why Urdu links look long when copied. - Encode each value, not the whole link. Encoding the
?and=that structure the URL breaks it.
Frequently asked questions
What does %20 mean in a URL?
It is the encoded form of a space character.
Why do URLs need encoding?
Some characters have special meanings or are not allowed in addresses, so they are replaced with percent codes.
Should I use spaces in page addresses?
No. Use hyphens in slugs to keep URLs clean and readable.
What is the difference between encodeURI and encodeURIComponent?
encodeURI keeps characters that structure a URL, while encodeURIComponent encodes them too, which is safer for single values.
Can I decode a URL to read it?
Yes. A URL decoder turns percent codes back into normal characters.
What is percent encoding?
It is the standard way to put special characters into a URL: each byte of the character is written as % followed by two hex digits, so a space becomes %20.
Should a space in a URL be %20 or +?
Use %20 in the path of a URL. A + only means a space inside form data in the query string, so %20 is the safe choice everywhere.
Why does my link contain %2520?
That is double encoding: the % of %20 was encoded again as %25. Decode the link once to get %20 back.