Encode and decode URL / URI components
URL encoding (also known as percent-encoding) converts special and non-ASCII characters in a URL into %XX format. Since URLs can only contain a limited ASCII character set, any reserved characters or non-Latin text must be encoded before being safely embedded in a URL.
| Function | Purpose | Characters NOT encoded |
|---|---|---|
encodeURI() |
Encode a full URL | Preserves :/?#[]@!$&'()*+,;=-._~ |
encodeURIComponent() |
Encode a parameter value | Only keeps letters, digits and -_.!~*'() |
Common encodings: space → %20, & → %26, = → %3D, + → %2B, # → %23
HTML forms (
application/x-www-form-urlencoded) encode spaces as+, while RFC 3986 uses%20— these are different encodings.
key=value&key2=value2 formatredirect_uri parameters in callback URLs%20 or +?It depends on context. URL paths and query parameters should use %20 (RFC 3986); application/x-www-form-urlencoded format (HTML form default) uses +. Prefer %20 for consistency and to avoid ambiguity.
The most common cause is a character encoding mismatch — the text was encoded using GBK/GB2312 but decoded as UTF-8. Verify the source data's character encoding. This tool uses UTF-8 by default.
Only encode parameter values. Using encodeURIComponent() on an entire URL will encode structural characters like ://, ?, and &, breaking the URL. Use encodeURI() for complete URLs.