How to URL encode or decode
- Paste your text, query value or URL into the Input box. Press Sample to try an example.
- Choose Encode for a single value, Encode full URL for a whole address, or Decode to turn
%XXcodes back into readable text. - Paste a full URL and the URL breakdown lists its host, path and every query parameter, already decoded.
- Press Copy or Download. Use Swap to feed the output back in, for example to check that decoding gives the original text.
How percent-encoding works
A URL may only contain a limited set of ASCII characters. Anything else is converted to its UTF-8 bytes,
and each byte is written as % plus two hexadecimal digits. Plain letters take one byte, accented letters two,
most Asian characters three and emoji four:
| Character | Encoded | Character | Encoded |
|---|---|---|---|
| space | %20 (or + in forms) | & | %26 |
! | %21 | = | %3D |
" | %22 | ? | %3F |
# | %23 | @ | %40 |
$ | %24 | / | %2F |
% | %25 | : | %3A |
+ | %2B | é | %C3%A9 |
, | %2C | € | %E2%82%AC |
Reserved and unreserved characters
RFC 3986, the standard for URLs, sorts characters into three groups:
- Unreserved:
A–Z a–z 0–9 - . _ ~. Always safe, never need encoding. - Reserved:
: / ? # [ ] @ ! $ & ' ( ) * + , ; =. They separate the parts of a URL, so they must be encoded when they appear inside a value. A search for "R&D" has to be sent asq=R%26D, otherwise the server sees a new parameter called D. - Everything else (spaces, quotes, < >, accented letters, emoji) must always be encoded.
Encode vs Encode full URL
| Encode (encodeURIComponent) | Encode full URL (encodeURI) | |
|---|---|---|
| Use for | One value: a search term, a name, a URL inside a parameter | A complete address with spaces or non-English characters |
/ ? & = : # | Encoded | Kept |
Input a b&c | a%20b%26c | a%20b&c |
A common bug is running a whole URL through Encode: the result https%3A%2F%2F… is no longer a working link. Another is encoding twice, which turns %20 into %2520.
URL encoding in code
| Language | Encode a value | Decode |
|---|---|---|
| JavaScript | encodeURIComponent(s) | decodeURIComponent(s) |
| Python | urllib.parse.quote(s, safe="") | urllib.parse.unquote(s) |
| PHP | rawurlencode($s) (%20) or urlencode($s) (+) | rawurldecode($s) |
| C# / .NET | Uri.EscapeDataString(s) | Uri.UnescapeDataString(s) |
| Java | URLEncoder.encode(s, UTF_8) (+ for spaces) | URLDecoder.decode(s, UTF_8) |
For HTML special characters such as < and & inside a web page, use the HTML entity encoder instead; for binary data, use Base64.
Comments 0
No comments yet.