A URL can only contain a limited set of characters, and some of those, such as ?, & and /, have special jobs. URL encoding, properly called percent-encoding, is how anything else gets into a URL safely: a space, an accented letter, an ampersand that is part of a search rather than a separator. Each such character is replaced by a % sign and two hexadecimal digits. Get it wrong and links break, search terms arrive mangled, or tracking parameters split in two.
Which characters are safe
The URL standard, RFC 3986, defines unreserved characters that never need encoding:
- the letters A–Z and a–z;
- the digits 0–9;
- the four symbols - . _ ~
Then there are reserved characters with special meanings, such as : / ? # [ ] @ ! $ & ’ ( ) * + , ; =. When one of these is used for its special purpose, such as the ? that starts a query, it stays as it is. When it is part of a value, such as an & inside a search term, it must be encoded. Everything else, including spaces and non-English letters, must always be encoded.
How a character is encoded
Take the character’s bytes in UTF-8, and write each byte as % followed by two hexadecimal digits:
- a space is one byte, 0x20, so it becomes %20;
- & becomes %26 and ? becomes %3F;
- é is two bytes in UTF-8, C3 A9, so it becomes %C3%A9.
So “café menu?” encoded as a value becomes caf%C3%A9%20menu%3F.
Encoding a value versus a whole URL
There are two different jobs, and mixing them up is the most common mistake.
Encoding one value, such as a search term or a parameter, encodes everything that could be mistaken for
structure. JavaScript’s encodeURIComponent does this:
- “leaking tap repair & parts” becomes leaking%20tap%20repair%20%26%20parts.
The & is encoded, so it stays part of the value.
Encoding a whole address leaves the structure alone and encodes only what is not allowed at all. JavaScript’s
encodeURI does this:
https://www.example.com/search?q=café menu&page=2becomeshttps://www.example.com/search?q=caf%C3%A9%20menu&page=2.
The ?, & and = are kept, because they give the URL its structure. But this is also the trap: if a value inside the query itself contains an & or =, encoding the whole URL will not protect it, and it will be read as a new parameter. Build URLs by encoding each value separately, then joining them.
The URL encoder and decoder does both jobs and decoding, line by line, so you can process a list at once, and reports any line with a broken % sequence.
Spaces: %20 or +?
There are two conventions:
- %20 is the standard percent-encoding of a space, valid anywhere in a URL.
- + for a space comes from HTML form encoding (application/x-www-form-urlencoded), used when a form is submitted. In that format, “leaking tap repair & parts” becomes leaking+tap+repair+%26+parts.
In a query string, many servers treat + as a space, but in a path a + is just a plus sign. When in doubt, use %20. When decoding form data, convert + back to a space before decoding the rest.
Where it matters in marketing
UTM parameters. Campaign names with spaces or ampersands must be encoded, or analytics will record them wrong. “Spring Sale & Clearance” as a campaign value must become Spring%20Sale%20%26%20Clearance, or the & will cut it short. The UTM builder encodes each value for you, and our guide on UTM naming conventions recommends lowercase names without spaces, which avoids most encoding altogether.
Page addresses. For your own pages, it is better to avoid characters that need encoding at all: lowercase letters, digits and hyphens. The URL slug generator turns a title into one, and our guide on URL structure best practices explains why.
Encoding in other languages
Every language has its own functions, and they do not all agree on spaces:
- Python:
urllib.parse.quoteencodes a space as %20, andquote_plusas +, following form encoding. - PHP:
rawurlencodeencodes a space as %20;urlencodeuses +. - JavaScript:
encodeURIComponentandencodeURIuse %20; theURLSearchParamsobject, which builds form-style query strings, uses +.
Pick the function that matches what the receiving system expects, and use the same one throughout a project.
Addresses with other alphabets
Browsers often show decoded characters in the address bar, so a page at /caf%C3%A9/ may display as /café/. The address sent to the server is still the encoded one. Domain names are different again: a domain with non-English letters is converted to an ASCII form called punycode, which is a separate mechanism from percent-encoding.
Double encoding
If an already-encoded value is encoded again, the % signs themselves get encoded: %20 becomes %2520. The result displays as a literal “%20” instead of a space. It usually means a value went through two systems that both encoded it. Encode exactly once, at the point where the value is put into the URL.
Decoding
Decoding reverses the process: every %XX becomes its byte, and the bytes are read as UTF-8. Decoding fails on a broken sequence, such as a % not followed by two hex digits, or bytes that are not valid UTF-8. A good decoder reports the problem rather than guessing.
Common questions
What is %20 in a URL? An encoded space.
What is the difference between encodeURI and encodeURIComponent? encodeURIComponent encodes a single value, including / ? & =; encodeURI encodes a whole URL and leaves those characters alone.
Should spaces be %20 or +? %20 is valid everywhere. + means a space only in form-encoded query strings.
Do I need to encode letters and numbers? No. Letters, digits and - . _ ~ never need encoding.
Limits of this guide
Browsers and servers are lenient in different ways, and some display decoded characters in the address bar. Test links in the systems that will read them.
Sources, read November 15, 2026:
- Wikipedia, Percent-encoding: RFC 3986 unreserved and reserved characters, encoding of UTF-8 bytes as % and two hex digits, and + for spaces in form data.