URL Encoding (Percent-Encoding) Explained
What percent-encoding is, which characters must be encoded in URLs, common codes like %20, and how to avoid encoding problems.
URLs can only contain a limited set of characters. Anything else, such as spaces, many symbols and non-ASCII letters, must be converted into a safe form called percent-encoding, also known as URL encoding.
How it works
Each unsafe character is converted to its byte value in UTF-8 and written as a percent sign followed by two hexadecimal digits.
| Character | Encoded |
|---|---|
| Space | %20 (or + in form data) |
& | %26 |
/ | %2F |
? | %3F |
# | %23 |
é | %C3%A9 |
Reserved characters
Some characters have special meanings in URLs:
?starts the query string.&separates parameters.=separates a parameter name and value.#starts a fragment (an in-page link)./separates path segments.
If these characters appear as data rather than structure, they must be encoded.
Where problems appear
- Spaces in file names producing links like
My%20Document%20Final.pdf. - Ampersands in titles breaking query strings.
- Accented characters creating long encoded links when copied.
- Double-encoding, where
%20becomes%2520.
Avoiding encoding issues
- Use clean slugs with only lowercase letters, numbers and hyphens. The slug generator produces exactly this, so slugs never need encoding.
- Rename files before uploading: no spaces or special characters.
- Use built-in functions in code, such as
encodeURIComponent()in JavaScript orrawurlencode()in PHP, rather than encoding by hand. - Encode each parameter value once, not the whole URL repeatedly.
Frequently asked questions
What is percent-encoding?
What is percent-encoding? It replaces unsafe characters with a percent sign and two hexadecimal digits. URL encoding explained simply: a space becomes %20 and é becomes %C3%A9.
Why avoid spaces in URLs?
Spaces in URLs become %20, which looks messy and breaks when copied into some apps. Special characters in URLs such as &, ? and # have special meanings and also need encoding. Clean slugs avoid both problems, unlike an encoded URL.
Try the free Slug Generator
Turn titles into clean, SEO-friendly URL slugs with bulk mode and smart trimming.
Open Slug Generator