URL Encoding Special Characters β Fix and Reference
π‘URL encoding converts special characters into percent-encoded sequences so they can be transmitted safely in a URL. The most common mistakes are using encodeURI instead of encodeURIComponent for parameter values, forgetting to encode & and =, and double-encoding an already-encoded string. Use encodeURIComponent for query parameter values and decode before re-encoding if the value is already encoded.
Quick Diagnosis
If you see βspaces in URL appear as + or %20β β it means both are valid but context-dependent β + is used in form data, %20 in path segments β do this: use encodeURIComponent for query parameter values (produces %20, not +)
If you see β& in query string breaks parameter parsingβ β it means & is a query string delimiter β literal & must be encoded as %26 β do this: encode parameter values with encodeURIComponent before appending to URL
If you see βURL works in browser but fails in API callβ β it means browser auto-corrects malformed URLs; the API receives the raw string β do this: always encode parameter values explicitly β do not rely on browser correction
If you see β%25 in URL (double-encoded percent)β β it means you encoded an already-encoded string β do this: decode first with decodeURIComponent, then re-encode the raw value
Common Fixes
Using encodeURI vs encodeURIComponent
β Wrong
// encodeURI does NOT encode & = ? β breaks query strings
const url = encodeURI("https://api.com/search?q=hello world&filter=a&b");
// β https://api.com/search?q=hello%20world&filter=a&b (& not encoded)β Fixed
// Encode only the value, not the entire URL
const q = encodeURIComponent("hello world&filter=a");
const url = `https://api.com/search?q=${q}`;
// β https://api.com/search?q=hello%20world%26filter%3DaencodeURI skips characters that are valid in a URL structure. Use encodeURIComponent for values only.
Non-ASCII characters (Γ©, ΓΌ, δΈ)
β Wrong
// Raw non-ASCII in URL β may fail on some servers
fetch("https://api.com/search?q=cafΓ©");
// β may be rejected or misinterpretedβ Fixed
// Encode to percent-encoded UTF-8 bytes
const q = encodeURIComponent("cafΓ©");
fetch(`https://api.com/search?q=${q}`);
// β https://api.com/search?q=caf%C3%A9Non-ASCII characters must be percent-encoded as UTF-8 bytes. encodeURIComponent handles this automatically.
Special Characters Quick Reference
space%20use %20 (not + outside form data)&%26query param delimiter β must encode in values=%3Dkey/value separator β encode in values+%2Bliteral plus β encode if not meaning a space#%23fragment delimiter β encode in query values/%2Fpath delimiter β encode in query values?%3Fquery start β encode in query valuesEncode and Decode URLs Instantly
Paste any URL or string to encode or decode it in the browser β see exactly what each special character becomes after encoding.
Related Guides
Frequently Asked Questions
What is the difference between encodeURI and encodeURIComponent?
encodeURI encodes a full URL and leaves characters like /, ?, &, = untouched. encodeURIComponent encodes everything except letters, digits, and - _ . ~ β use it for query parameter values.
Should I use %20 or + for spaces in URLs?
Use %20 in path segments and encodeURIComponent output. The + sign for spaces only works in application/x-www-form-urlencoded bodies and is not safe in path or query string contexts.
How do I avoid double-encoding?
Only encode values that are not already encoded. If the value may already be encoded, decode it with decodeURIComponent first, then re-encode the plain value.
All tools run in your browser. Your data never leaves your device.