Encode or decode URLs with three distinct encoding strategies: encodeURI (preserves URL structure), encodeURIComponent (escapes reserved characters for use in query parameters), and application/x-www-form-urlencoded (spaces become +). Decode mode handles both conventions.
- What's the difference between encodeURI and encodeURIComponent?
- encodeURI preserves URL-structural characters like :, /, ?, #, and & — use it on a full URL. encodeURIComponent escapes those characters too, so it's safe for query-string values or path segments you want to inject into a URL.
- When should I use form-urlencoded encoding?
- Use it when building application/x-www-form-urlencoded bodies for HTML form submissions or POST requests. It's identical to encodeURIComponent except spaces become + instead of %20.
- Which characters stay unescaped?
- Unreserved characters A-Z, a-z, 0-9, and - _ . ~ are never percent-encoded. encodeURI additionally keeps reserved URI delimiters (:/?#[]@!$&'()*+,;=) intact.