Guide
URL Encoding Explained
URL encoding keeps URLs unambiguous when values contain spaces, symbols, separators, or non-ASCII text.
Related tools
Reserved characters
URLs use characters such as ?, &, =, /, :, and # as syntax. When those characters are part of a value instead of the URL structure, they need encoding so parsers do not misread them.
Query string values
Query parameters are a common place for bugs. If a value contains an ampersand and it is not encoded, the server may treat it as the start of another parameter.
Use component encoding for individual values. Use full URI encoding only when you already have a complete URL and want to preserve URL separators.
Spaces, plus signs, and percent encoding
Percent encoding represents bytes with sequences such as %20. Form-style query encoding often represents spaces as plus signs. A literal plus sign and a space can therefore be confused if code decodes with the wrong assumptions.
Common bugs
- Encoding an entire URL as a component and turning every separator into percent escapes.
- Forgetting to encode redirect URLs nested inside query parameters.
- Double-encoding an already encoded value.
- Decoding a malformed percent sequence without error handling.
FAQ
Should I use encodeURI or encodeURIComponent?
Use encodeURIComponent for values and encodeURI for complete URLs where separators should remain as URL syntax.
Why does plus sometimes decode to a space?
That behavior comes from form-style query encoding, not from percent decoding in every context.