URL Encode & Decode
Make text safe to put in a URL, or turn %20-style sequences back into readable characters. The tool uses your browser's own encodeURIComponent, encodeURI and decodeURIComponent, lists query parameters in a table, and sends nothing to a server.
0 characters · 0 words · 0 lines
0 characters · 0 words · 0 lines
Runs entirely in this browser tab. Your text is never uploaded or stored.
What each function escapes
Computed with the browser functions themselves. encodeURIComponent leaves letters, digits and these marks alone: ! ' ( ) * - . _ ~
| Character | encodeURIComponent | encodeURI |
|---|---|---|
(space) | %20 | %20 |
! | ! | ! |
" | %22 | %22 |
# | %23 | # |
$ | %24 | $ |
% | %25 | %25 |
& | %26 | & |
' | ' | ' |
( | ( | ( |
) | ) | ) |
* | * | * |
+ | %2B | + |
, | %2C | , |
/ | %2F | / |
: | %3A | : |
; | %3B | ; |
= | %3D | = |
? | %3F | ? |
@ | %40 | @ |
[ | %5B | %5B |
] | %5D | %5D |
{ | %7B | %7B |
} | %7D | %7D |
| | %7C | %7C |
\ | %5C | %5C |
^ | %5E | %5E |
` | %60 | %60 |
< | %3C | %3C |
> | %3E | %3E |
~ | ~ | ~ |
- | - | - |
_ | _ | _ |
. | . | . |
é | %C3%A9 | %C3%A9 |
€ | %E2%82%AC | %E2%82%AC |
😀 | %F0%9F%98%80 | %F0%9F%98%80 |
Percent-encoding and the reserved characters of RFC 3986
A URL may only contain a limited set of ASCII characters. RFC 3986, the 2005 specification for URI syntax, splits them into two groups. The unreserved characters, A–Z, a–z, 0–9 and the four marks - . _ ~, never need encoding. The reserved characters have jobs: the general delimiters : / ? # [ ] @ separate scheme, host, path, query and fragment, and the sub-delimiters ! $ & ' ( ) * + , ; = separate items within them, as & and = do in a query string. Everything else, and any reserved character used as plain data, must be percent-encoded.
Percent-encoding writes a byte as % followed by two hexadecimal digits. Text is first converted to UTF-8, so a space becomes %20, an é (two bytes) becomes %C3%A9 and an emoji becomes four %XX groups. That is why a search for "café & bar" ends up in a link as caf%C3%A9%20%26%20bar: the & is encoded so the server does not read it as the start of a new parameter.
encodeURIComponent, encodeURI and decoding
encodeURIComponent is the right choice for a single piece, such as a query value, a path segment or a redirect URL passed as a parameter. It escapes everything except the unreserved characters and ! ' ( ) *, which JavaScript leaves alone for historical reasons. encodeURI (whole URL) assumes its input is already a complete address and keeps the reserved characters intact, so https://example.com/a b?q=1 only has its space encoded. Using encodeURI on a parameter value is a classic bug: an & or # inside the value would survive and break the URL.
Decode reverses either function. HTML forms submitted with GET use the older application/x-www-form-urlencoded format, in which a space is written as + rather than %20; keep Treat + as a space ticked for those, and untick it when a literal plus sign matters, as in a phone number. If the input contains a % that is not followed by two hex digits, or bytes that are not valid UTF-8, decoding fails with a clear message instead of guessing. When the text contains a query string, its parameters appear decoded in a table below the tool. For binary data in URLs, Base64url is the usual alternative.
Frequently asked questions
- Should a space in a URL be %20 or a plus sign?
- In paths and in RFC 3986 terms, a space is %20. The + form only means a space inside query strings encoded the way HTML forms encode them, so %20 is the safe choice everywhere.
- Why did my URL end up with %2520 in it?
- It was encoded twice. The first pass turned a space into %20, and the second encoded the % itself as %25. Decode once to undo the extra layer, and encode values only at one point in your code.
- Which characters never need percent-encoding?
- The unreserved set of RFC 3986: the letters A to Z in both cases, the digits 0 to 9, and the hyphen, period, underscore and tilde.
- Can a URL contain non-English letters without encoding?
- Browsers display them, but on the wire every non-ASCII character in a path or query is sent as percent-encoded UTF-8. Domain names use a separate system, Punycode, which turns them into xn-- labels.
- Why does decoding report a malformed sequence?
- The text has a % that is not followed by two hexadecimal digits, such as a literal "100%", or the bytes decode to invalid UTF-8. Encode stray % signs as %25 before decoding.