URL Encoding Guide
What is URL Encoding?
URL encoding (percent encoding) replaces unsafe characters with a % followed by two hexadecimal digits. For example, a space becomes %20. This ensures URLs are valid and can be transmitted safely.
Common Encoded Characters
| Character | Encoded | Purpose |
|---|---|---|
| (space) | %20 | Spaces in URLs |
| & | %26 | Parameter separator |
| = | %3D | Key-value assignment |
| # | %23 | Fragment identifier |
| / | %2F | Path separator |
Code Examples
// JavaScript
encodeURIComponent("hello world & more") // "hello%20world%20%26%20more"
decodeURIComponent("hello%20world") // "hello world"
// encodeURI vs encodeURIComponent
encodeURI("https://example.com/path?q=hello world")
// "https://example.com/path?q=hello%20world"
encodeURIComponent("https://example.com/path")
// "https%3A%2F%2Fexample.com%2Fpath"Common Mistakes
- Double encoding: Encoding an already-encoded string gives
%2520instead of%20. - Using encodeURI for query values: Use
encodeURIComponentfor individual parameter values. - + vs %20: In query strings,
+represents a space (form encoding), but in paths only%20is valid.
Encode and decode URLs with our URL Encoder/Decoder. Parse query parameters with the Query String Parser.
FAQ
What's the difference between encodeURI and encodeURIComponent?
encodeURI encodes a full URI, preserving :, /, ?, #. encodeURIComponent encodes everything except alphanumeric and - _ . ~ characters.