encodeURIComponent encodes everything except A-Z a-z 0-9 - _ . ! ~ * ' ( ) β use for individual parameters.
encodeURI preserves URL structure chars like : / ? # [ ] @ ! $ & ' ( ) * + , ; = β use for full URLs.
URLs can only contain a limited set of ASCII characters. Any character outside that set β including spaces, accented letters, emoji, and many punctuation marks β must be percent-encoded (also called URL encoding). Each disallowed character is replaced by a % followed by its two-digit hexadecimal code point.
For example: space becomes %20, & becomes %26, and = becomes %3D.
| Function | Preserves | Encodes | Use for |
|---|---|---|---|
encodeURIComponent() | A-Z a-z 0-9 - _ . ! ~ * ' ( ) | Everything else, including : / ? # & = | Individual query parameter values |
encodeURI() | URL structure chars: : / ? # [ ] @ ! $ & ' ( ) * + , ; = | Spaces, accented letters, non-ASCII | A complete URL that already has structure |
| Scenario | Input | Correct function | Result |
|---|---|---|---|
| Query parameter value | hello world & more | encodeURIComponent | hello%20world%20%26%20more |
| Full URL with path | https://example.com/path?q=1 | encodeURI | Unchanged (already valid) |
| URL with spaces in path | https://example.com/my file.pdf | encodeURI | https://example.com/my%20file.pdf |
| API parameter with JSON | {"key":"val"} | encodeURIComponent | %7B%22key%22%3A%22val%22%7D |
© 2026, Tinker - tools Β· calculators Β· practice games