encodeURIComponent · encodeURI
URL Encoder/Decoder
Percent-encode text for a URL, or decode %XX escapes back into readable text. Pick encodeURIComponent or encodeURI, work line by line, see the UTF-8 bytes, and get a clear message when decoding fails.
- 100% in your browser
- Same output as JavaScript
- Double-encoding check
Processed in your browser · nothing is uploaded
For a query value, path segment or form field: encodes everything except A–Z a–z 0–9 - _ . ! ~ * ' ( )
UTF-8 percent-encoding preview
Each character that is encoded, with its UTF-8 bytes.
| Character | Code point | UTF-8 bytes | Encoded |
|---|---|---|---|
| 重 | U+91CD | E9 87 8D | %E9%87%8D |
| 庆 | U+5E86 | E5 BA 86 | %E5%BA%86 |
| 火 | U+706B | E7 81 AB | %E7%81%AB |
| 锅 | U+9505 | E9 94 85 | %E9%94%85 |
| space | U+0020 | 20 | %20 |
| 攻 | U+653B | E6 94 BB | %E6%94%BB |
| 略 | U+7565 | E7 95 A5 | %E7%95%A5 |
| è | U+00E8 | C3 A8 | %C3%A8 |
| û | U+00FB | C3 BB | %C3%BB |
| é | U+00E9 | C3 A9 | %C3%A9 |
This URL encoder and decoder percent-encodes text so it can travel safely inside a URL, and decodes %XX escapes back into readable text. Choose encodeURIComponent for a single query value or path segment, or encodeURI for a whole address, convert every line on its own, and see the UTF-8 bytes behind each escape. When a string cannot be decoded, the tool tells you which line, which column and why. Everything runs in your browser.
encodeURIComponent vs encodeURI
Both functions turn each character outside a small safe set into its UTF-8 bytes, written as % plus two hex digits. They differ in what they leave alone:
| Input | encodeURIComponent | encodeURI |
|---|---|---|
重庆火锅 | %E9%87%8D%E5%BA%86%E7%81%AB%E9%94%85 | %E9%87%8D%E5%BA%86%E7%81%AB%E9%94%85 |
Crème Brûlée | Cr%C3%A8me%20Br%C3%BBl%C3%A9e | Cr%C3%A8me%20Br%C3%BBl%C3%A9e |
Tom & Jerry | Tom%20%26%20Jerry | Tom%20&%20Jerry |
50% off? | 50%25%20off%3F | 50%25%20off? |
path/to/file | path%2Fto%2Ffile | path/to/file |
https://example.com/搜索?q=咖啡 豆&page=2#top | https%3A%2F%2Fexample.com%2F%E6%90%9C%E7%B4%A2%3Fq%3D%E5%92%96%E5%95%A1%20%E8%B1%86%26page%3D2%23top | https://example.com/%E6%90%9C%E7%B4%A2?q=%E5%92%96%E5%95%A1%20%E8%B1%86&page=2#top |
- encodeURIComponent keeps only
A–Z a–z 0–9 - _ . ! ~ * ' ( ). Use it for anything you put inside a URL: a query value, a path segment, a form field. Characters such as&,=,?,/and#are encoded, so they cannot break the URL apart. - encodeURI also keeps
; , / ? : @ & = + $ #, so a complete URL still works after encoding. Never use it for a single value:Tom & Jerrywould leave the&in place and split your query string.
A Chinese character takes three UTF-8 bytes, so it becomes nine characters of encoded text; an accented Latin letter takes two bytes. Readable ASCII slugs avoid this; see how to transliterate slugs.
Spaces: %20 or a plus sign?
In a URL path and with encodeURIComponent, a space is %20. HTML forms send data as application/x-www-form-urlencoded, where a space is written as + and a real plus sign as %2B: a b+c becomes a+b%2Bc. Turn on "Spaces as +" to encode or decode form data. Without it, the decoder leaves + as a plus sign, exactly like decodeURIComponent.
Why decoding fails
decodeURIComponent throws a URIError on two kinds of input, and this tool reports the exact position instead:
- A % without two hex digits.
100%or%zzis not a valid escape. If the text means a literal percent sign, it should have been encoded as%25. - Bytes that are not UTF-8.
%E4%B8is a Chinese character cut short (it needs three bytes), andcaf%E9was encoded as Latin-1 rather than UTF-8. Re-encode the original text as UTF-8, or fix the truncated part.
With "Each line separately" on, a failing line is kept unchanged and every other line is still decoded.
Double encoding
Encoding an already-encoded string turns each % into %25: é becomes %C3%A9, and encoding again gives %25C3%25A9. It usually happens when a value is encoded once by your code and again by a library or CMS. The tool warns when you encode text that already contains escapes, and when decoded text still looks encoded it offers "Decode fully", which repeats the decode until nothing changes: caf%25C3%25A9 → caf%C3%A9 → café.
Code: the same encoding in JavaScript, Python and PHP
These functions give exactly the tool's output (checked against it for every test string):
// Query values, path segments, form fields: encode everything except A-Z a-z 0-9 - _ . ! ~ * ' ( )
encodeURIComponent('Café & Bar?'); // 'Caf%C3%A9%20%26%20Bar%3F'
decodeURIComponent('Caf%C3%A9'); // 'Café' (throws URIError on bad input such as '100%')
// A whole URL: keeps ; , / ? : @ & = + $ # so the URL still works
encodeURI('https://example.com/a b?q=café'); // 'https://example.com/a%20b?q=caf%C3%A9'from urllib.parse import quote, unquote
def encode_uri_component(s): # same output as JavaScript's encodeURIComponent
return quote(s, safe="-_.!~*'()")
def encode_uri(s): # same output as JavaScript's encodeURI
return quote(s, safe="-_.!~*'();,/?:@&=+$#")
def decode_uri_component(s): # raises on invalid UTF-8 such as '%E9'; a stray '%' is kept as is
return unquote(s, errors='strict')<?php
// rawurlencode() also encodes ! * ' ( ); put them back to match encodeURIComponent exactly.
function encode_uri_component(string $s): string {
return strtr(rawurlencode($s), ['%21' => '!', '%2A' => '*', '%27' => "'", '%28' => '(', '%29' => ')']);
}
function decode_uri_component(string $s): string {
return rawurldecode($s); // keeps "+" as "+"; use urldecode() for form data
}For a URL slug you rarely need encoding at all: the URL slug generator turns titles into lowercase ASCII words joined by hyphens, which never need escaping. To strip accents from text without making a slug, use the remove accents tool.
Sources
- MDN: encodeURIComponent() and encodeURI()
- RFC 3986: Uniform Resource Identifier, section 2: Characters
- Python documentation: urllib.parse.quote()
FAQ
Frequently asked questions
What is URL encoding?
URL encoding, or percent-encoding, writes each character that is not allowed in a URL as its UTF-8 bytes, each shown as % plus two hex digits. A space becomes %20 and é becomes %C3%A9.
When should I use encodeURIComponent instead of encodeURI?
Use encodeURIComponent for one piece of a URL, such as a query value or a path segment. Use encodeURI only for a complete URL whose /, ?, & and # must keep working.
Why do I get "URIError: URI malformed"?
The text has a % that is not followed by two hex digits, such as 100%, or escapes that are not valid UTF-8, such as %E4%B8. The tool shows the line and column of the first problem.
How do I fix a double-encoded URL?
Decode it until it stops changing. A value like caf%25C3%25A9 needs two decodes; the "Decode fully" button does this for you.
Should a space be %20 or +?
Use %20 in URL paths and with encodeURIComponent. A + means a space only in form data and query strings sent as application/x-www-form-urlencoded.
Is my text sent to a server?
No. Encoding and decoding use your browser's own JavaScript functions, and nothing you paste leaves your device.
Want readable URLs instead of %E4%B8%AD?
Turn titles into short ASCII slugs, so links stay readable even when they are percent-encoded.
