Percent-encode text for URLs or decode encoded strings -- free, private, in your browser
Read more: URL Encoder & Decoder
URL encoding, also called percent-encoding, is the method of representing characters in a URL using a percent sign followed by two hexadecimal digits. For example, a space becomes %20 and an ampersand becomes %26. This encoding is defined by RFC 3986 and ensures that special characters do not break the structure of a URL.
URLs can only contain a limited set of characters from the ASCII character set. Characters outside the unreserved set (letters, digits, hyphens, underscores, periods, and tildes) must be percent-encoded when they appear in URL components like query parameter values. This includes spaces, punctuation, and all non-ASCII characters like accented letters or CJK characters.
:, /, ?, and #encodeURIComponent encodes everything except unreserved characters (letters, digits, -_.~). Use it for query parameter values, path segments, or any piece of data that will be embedded into a URL. This is the right choice in most situations.
encodeURI preserves characters that have structural meaning in URLs: : / ? # [ ] @ ! $ & ' ( ) * + , ; =. Use it only when you have a complete URL and want to fix illegal characters (like spaces or non-ASCII characters) without breaking the URL structure.
Example: encoding the string hello world&foo=bar
encodeURIComponent: hello%20world%26foo%3Dbar -- safe for use as a parameter valueencodeURI: hello%20world&foo=bar -- preserves & and =, would break if this were a parameter value| Character | Encoded | Notes |
|---|---|---|
| Space | %20 | + in form data (application/x-www-form-urlencoded) |
& | %26 | Separates query parameters |
= | %3D | Separates key from value |
? | %3F | Starts query string |
# | %23 | Fragment identifier |
/ | %2F | Path separator |
+ | %2B | Often confused with space |
@ | %40 | Used in email addresses and userinfo |
% | %25 | The escape character itself |
The %20 encoding comes from RFC 3986 and is the standard percent-encoding for a space. The + encoding comes from the older application/x-www-form-urlencoded format used by HTML forms. Both are valid, but %20 is always safe. Use encodeURIComponent, which produces %20, for general-purpose URL encoding.
Encode only the parts that contain user data or special characters -- typically query parameter values. If you encode an entire URL with encodeURIComponent, you will break it by encoding the slashes, colons, and question marks that give it structure. Use encodeURIComponent for values and encodeURI for complete URLs.
Non-ASCII characters are first encoded as UTF-8 bytes, then each byte is percent-encoded. For example, the character "n" (U+00F1) becomes the UTF-8 bytes C3 B1, which are encoded as %C3%B1. JavaScript's encodeURIComponent handles this automatically.