Encode special characters in URLs or decode percent-encoded strings. Essential for web development, API testing, and debugging query parameters.
URL encoding (also called percent encoding) replaces unsafe ASCII characters with a % followed by their hexadecimal value. This is necessary because URLs can only contain a limited set of characters from the ASCII set. Characters like spaces, &, =, and non-ASCII characters must be encoded for proper URL handling.
| Function | Encodes | Preserves | Use Case |
|---|---|---|---|
| encodeURI | Spaces, non-ASCII | :/?#[]@!$&'()*+,;= | Encoding complete URLs |
| encodeURIComponent | All special chars | Only A-Z, 0-9, - _ . ~ | Encoding query parameters |
| Character | Encoded | Character | Encoded |
|---|---|---|---|
| Space | %20 or + | & | %26 |
| = | %3D | ? | %3F |
| # | %23 | / | %2F |
| @ | %40 | : | %3A |
%20 is the standard URL encoding for space. The + sign is only used in query strings (application/x-www-form-urlencoded format). In path segments, always use %20.
No. Only encode individual parameter values using encodeURIComponent(). If you encode the entire URL with encodeURIComponent, it will also encode the slashes and colons, breaking the URL structure.