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.