The Complete Guide to URL Encoding: Why Your Links Are Broken
Why Spaces Break the Internet
The internet's address system (URLs) was designed to only handle a specific set of safe ASCII characters. Spaces are not allowed. If you try to send a request like example.com/my file.pdf, the server interprets the space as the end of the URL, and your request fails. To fix this, browsers and servers use Percent Encoding.
How Encoding Works
Percent encoding replaces unsafe characters with a % followed by two hexadecimal digits representing their ASCII value. The most common example is the space character, which becomes %20. Other common encodings include:
- Space: %20
- Forward Slash (/): %2F
- Question Mark (?): %3F
- Ampersand (&): %26
encodeURI vs. encodeURIComponent
For JavaScript developers, knowing which function to use is critical:
- encodeURI(): Use this when you want to encode a full URL. It preserves characters like
: / ? # so the URL remains valid. - encodeURIComponent(): Use this when you are encoding a value inside a query parameter (e.g.,
?name=val). It encodes everything, including slashes and question marks.
Debugging Broken Links
If you see a "400 Bad Request" error, it's often because a reserved character wasn't encoded properly. Use our URL Encoder to fix your strings instantly.
Related Tools