URL Encoder / Decoder
Percent-encode or decode text and URLs. Component, full-URL and form (+) modes, UTF-8 safe, exact errors for bad % sequences, and a URL parser.
Parse a URL
| Part | Value | Decoded |
|---|
Query parameters
URLSearchParams writes it.Type or paste text to percent-encode it, or switch to Decode. Choose the mode that matches where the text is going: Component for a single query value or path segment, Full URL for a whole address, and Form for application/x-www-form-urlencoded data, where a space becomes +. The Parse a URL panel splits an address into its parts and lets you edit the query parameters. Everything runs in your browser.
Why URLs need encoding
A URL can contain only a limited set of ASCII characters, and several of them have jobs: / separates path segments, ? starts the query, & and = split it into name/value pairs, and # starts the fragment. If a value contains one of those characters, or a space, an accented letter or an emoji, it has to be written as a percent sign followed by the byte's two hex digits. RFC 3986 calls this percent-encoding.
Take the value "fish & chips". Dropped straight into ?dish=fish & chips, the & ends the parameter early: the server sees dish set to "fish " and a second parameter named " chips" with no value. Encoded, it is fish%20%26%20chips (component) or fish+%26+chips (form), and arrives intact.
Reserved and unreserved characters
RFC 3986 sorts characters into groups:
- Unreserved:
AโZ aโz 0โ9 - . _ ~. These never need encoding. - Reserved, general delimiters:
: / ? # [ ] @. They mark the parts of a URL. - Reserved, sub-delimiters:
! $ & ' ( ) * + , ; =. They have meanings inside a part, such as&and=in a query.
Anything else, including spaces, quotes, < >, braces and all non-ASCII characters, must always be encoded. Reserved characters must be encoded when they are data rather than structure.
How each function encodes common characters
Gray means the character is left as it is. The columns do not all agree, and the differences are where bugs come from:
| Char | Role | encodeURIComponent | encodeURI | rawurlencode (RFC 3986) | Form / URLSearchParams | PHP urlencode |
|---|---|---|---|---|---|---|
(space) | space | %20 | %20 | %20 | + | + |
! | ! | ! | %21 | %21 | %21 | |
" | %22 | %22 | %22 | %22 | %22 | |
# | fragment | %23 | # | %23 | %23 | %23 |
$ | %24 | $ | %24 | %24 | %24 | |
% | escape marker | %25 | %25 | %25 | %25 | %25 |
& | separates parameters | %26 | & | %26 | %26 | %26 |
' | ' | ' | %27 | %27 | %27 | |
( | ( | ( | %28 | %28 | %28 | |
) | ) | ) | %29 | %29 | %29 | |
* | * | * | %2A | * | %2A | |
+ | space in forms | %2B | + | %2B | %2B | %2B |
, | %2C | , | %2C | %2C | %2C | |
/ | path separator | %2F | / | %2F | %2F | %2F |
: | %3A | : | %3A | %3A | %3A | |
; | %3B | ; | %3B | %3B | %3B | |
< | %3C | %3C | %3C | %3C | %3C | |
= | name=value | %3D | = | %3D | %3D | %3D |
> | %3E | %3E | %3E | %3E | %3E | |
? | starts the query | %3F | ? | %3F | %3F | %3F |
@ | %40 | @ | %40 | %40 | %40 | |
[ | %5B | %5B | %5B | %5B | %5B | |
\ | %5C | %5C | %5C | %5C | %5C | |
] | %5D | %5D | %5D | %5D | %5D | |
^ | %5E | %5E | %5E | %5E | %5E | |
` | %60 | %60 | %60 | %60 | %60 | |
{ | %7B | %7B | %7B | %7B | %7B | |
| | %7C | %7C | %7C | %7C | %7C | |
} | %7D | %7D | %7D | %7D | %7D | |
~ | unreserved | ~ | ~ | ~ | %7E | %7E |
- | unreserved | - | - | - | - | - |
. | unreserved | . | . | . | . | . |
_ | unreserved | _ | _ | _ | _ | _ |
Three differences are worth knowing:
- Space:
%20everywhere except form encoding, which uses+. Both are common in query strings, but only%20means a space in a path. ! ' ( ) *: JavaScript'sencodeURIComponentleaves these alone because it follows the older RFC 2396 list of safe "mark" characters, while PHP'srawurlencodefollows RFC 3986 and encodes them. Both results decode to the same text. Tick Also encode ! ' ( ) * in Component mode to match RFC 3986 exactly.~: unreserved in RFC 3986, so most functions keep it, but form encoding and PHP'surlencodewrite%7E. Python'squote_pluskeeps it.
Non-ASCII characters: UTF-8 first, then percent-encode
A character outside ASCII is first converted to its UTF-8 bytes, and each byte is encoded separately. One character can become up to four escapes:
| Character | Code point | UTF-8 bytes | Hex | Encoded |
|---|---|---|---|---|
| รฉ | U+00E9 | 2 | C3 A9 | %C3%A9 |
| รฑ | U+00F1 | 2 | C3 B1 | %C3%B1 |
| โฌ | U+20AC | 3 | E2 82 AC | %E2%82%AC |
| ๆฅ | U+65E5 | 3 | E6 97 A5 | %E6%97%A5 |
| ๐ | U+1F44D | 4 | F0 9F 91 8D | %F0%9F%91%8D |
So "cafรฉ" becomes caf%C3%A9. Browsers often display the decoded form in the address bar but send the encoded bytes. A decoder must put the bytes back together before turning them into text, which is why a broken sequence fails as a whole: %E0%A4%A is the first two bytes of "เค" (%E0%A4%95) plus a cut-off escape, and JavaScript's decodeURIComponent throws a URIError on it ("URI malformed" in Chrome). This tool reports the exact position instead.
Which mode to use
| You are encoding | Use | Example |
|---|---|---|
| One query parameter value | Component (encodeURIComponent) | "fish & chips" โ fish%20%26%20chips |
| One path segment containing a slash | Component | "AC/DC" โ AC%2FDC |
| A whole URL with spaces or accents in it | Full URL (encodeURI) | https://example.com/a%20path/?q=caf%C3%A9&x=1 |
An HTML form body or URLSearchParams | Form | "fish & chips" โ fish+%26+chips |
Never run a whole URL through Component mode: it encodes the structure too, turning https:// into https%3A%2F%2F. And Full URL mode will not protect a value that contains &, = or #; encode each value with Component mode first, then assemble the URL.
Double encoding and other pitfalls
Double encoding happens when text that is already encoded is encoded again. The % itself becomes %25: "a b" encodes to a%20b, and encoding that gives a%2520b. The server decodes once and sees a literal "%20". Common causes are encoding in both your code and a library, or running encodeURI on a URL that came from a link. This tool warns when the input already contains escapes, and in Full URL mode it can leave existing ones alone.
Plus signs are the reverse problem. In form data + means a space, so "C++" must be sent as C%2B%2B. If it is sent unencoded, a form decoder such as PHP's urldecode returns "Cโฃโฃ" (C and two spaces). When decoding here, tick Treat + as a space only for form data.
Decoding too early breaks URLs as well. If you decode a whole URL and then parse it, an encoded %26 inside a value turns back into & and splits the parameter. Parse first, then decode each piece; the URL parser above does it in that order. Encoding is not a security control either: to put text into HTML, escape it with the HTML encoder, and to pass binary data in a URL, use URL-safe Base64 from the Base64 encoder.
URL encoding in code
// JavaScript
encodeURIComponent('fish & chips') // fish%20%26%20chips
new URLSearchParams({ dish: 'fish & chips' }).toString() // dish=fish+%26+chips
decodeURIComponent('caf%C3%A9') // cafรฉ
# Python
from urllib.parse import quote, quote_plus, urlencode
quote('fish & chips', safe='') # fish%20%26%20chips
quote_plus('fish & chips') # fish+%26+chips
urlencode({'dish': 'fish & chips'}) # dish=fish+%26+chips
// PHP
rawurlencode('fish & chips'); // fish%20%26%20chips
urlencode('fish & chips'); // fish+%26+chips
http_build_query(['dish' => 'fish & chips']); // dish=fish+%26+chips
Python's quote() keeps / unless you pass safe='', so it suits paths more than values. Java's URLEncoder.encode produces form encoding with + for spaces, despite its name. To test a request with encoded parameters, build it in the cURL command builder, and to turn a title into a URL path that needs no encoding at all, use the slug generator.