Dev.to
7/13/2026

The original title is: "URL Encoding Decoded: A Developer's Guide to encodeURI vs encodeURIComponent"
Original: URL Encoding Decoded: A Developer's Guide to encodeURI vs encodeURIComponent
Short summary
A developer's guide to JavaScript's encodeURI vs encodeURIComponent, explaining when to use each to avoid common URL-encoding bugs. encodeURI preserves URL-structural characters for full URLs, while encodeURIComponent encodes everything for query parameter values. The article recommends URLSearchParams as the safest approach for building query strings.
- •Use encodeURI for full URLs; it preserves structural characters like ?, &, =, #, /
- •Use encodeURIComponent for individual query parameter values to encode everything
- •Prefer URLSearchParams over manual concatenation for correct, browser-safe encoding
Generated with AI, which can make mistakes.
Is this a good recommendation for you?



