URL Encoder & Decoder
Percent-encode URLs and query parameters in your browser. Nothing uploaded.
URL encoding (percent-encoding) converts special characters into %XX sequences so they can safely appear in URLs. Use encodeURI for complete URLs (preserves :/?#&=) or encodeURIComponent for individual values like query parameters (encodes everything except A-Za-z0-9-_.!~*'()). Spaces become %20, not +.
encodeURI vs encodeURIComponent
Both functions percent-encode non-ASCII characters as UTF-8 bytes, but they differ in which ASCII characters they leave unencoded:
| Function | Characters left unencoded | Use for |
|---|---|---|
| encodeURI | A-Za-z0-9 ;,/?:@&=+$-_.!~*'()# | Complete URLs |
| encodeURIComponent | A-Za-z0-9 -_.!~*'() | Query values, path segments |
Common percent-encoded characters
| Character | Encoded | Description |
|---|---|---|
| (space) | %20 | Space character |
| & | %26 | Query parameter separator |
| = | %3D | Key-value separator |
| ? | %3F | Query string start |
| / | %2F | Path separator |
| + | %2B | Plus sign |
| # | %23 | Fragment identifier |
JavaScript examples
Encoding a query parameter
const query = 'hello world & goodbye';
const encoded = encodeURIComponent(query);
// "hello%20world%20%26%20goodbye"
const url = `https://example.com/search?q=${encoded}`;
// "https://example.com/search?q=hello%20world%20%26%20goodbye"Encoding a complete URL
const url = 'https://example.com/path/to file?q=hello world'; const encoded = encodeURI(url); // "https://example.com/path/to%20file?q=hello%20world" // Note: : / ? = are preserved
Decoding a URL
const encoded = 'hello%20world%20%26%20goodbye'; const decoded = decodeURIComponent(encoded); // "hello world & goodbye"
URL encode in JavaScript
JavaScript provides three ways to URL-encode strings, each with different use cases:
encodeURIComponent vs encodeURI
Use encodeURIComponent for query parameter values. Use encodeURI for complete URLs where you want to preserve the structure (:/?#&=).
// For query parameter values const value = 'hello world & goodbye'; const param = encodeURIComponent(value); // "hello%20world%20%26%20goodbye" // For complete URLs const url = 'https://example.com/path?q=hello world'; const encoded = encodeURI(url); // "https://example.com/path?q=hello%20world"
URLSearchParams
URLSearchParams builds query strings with form-style encoding, where spaces become + instead of %20.
const params = new URLSearchParams({
q: 'hello world',
page: '1'
});
params.toString();
// "q=hello+world&page=1"%20 vs + for spaces
encodeURIComponent uses %20 (RFC 3986).URLSearchParams uses + (application/x-www-form-urlencoded). Both are valid—%20 works everywhere, while + is specific to form submissions.
Decode URL-encoded text
Use decodeURIComponent to reverse percent-encoding and restore the original text. It converts sequences like %20 back to spaces and decodes UTF-8 byte sequences to characters.
Handling URIError: URI malformed
Both decodeURI and decodeURIComponent throw a URIError when they encounter malformed percent sequences:
- A lone
%sign not followed by two hex digits - An incomplete sequence like
%2 - Invalid hex pairs like
%ZZ
try {
decodeURIComponent('%ZZ'); // Invalid hex
} catch (e) {
console.error(e.name); // "URIError"
console.error(e.message); // "URI malformed"
}Plus signs are not spaces
decodeURIComponent does not convert + to spaces. The input hello+world stays as hello+world after decoding. The plus-as-space convention is specific to application/x-www-form-urlencoded (HTML form submissions). Use URLSearchParams if you need to parse form-encoded query strings where + represents a space.
Encode query string values
Use encodeURIComponent to percent-encode individual query parameter values. It escapes all characters except A-Za-z0-9 - _ . ! ~ * ' ( ), making the value safe to embed in a URL without breaking the query string structure.
%20 vs + for spaces
encodeURIComponent follows RFC 3986 and encodes spaces as %20. The + notation for spaces comes from the older HTML form encoding standard (application/x-www-form-urlencoded).
If you need form-style encoding with + for spaces (for example, when building a POST body), use URLSearchParams instead:
new URLSearchParams({ q: 'hello world' }).toString();
// "q=hello+world"Percent-encoding in Python and Node
The snippets below percent-encode UTF-8 bytes with %20 for spaces, the same RFC 3986 style this page's encodeURIComponent (Encode component) uses. They are not form encoding (+ for spaces). For that convention, see URLSearchParams vs encodeURIComponent: Form vs Percent-Encoding.
Node.js with encodeURIComponent
Node uses the same ECMA-262 functions as this page. Spaces become %20, and ! ' ( ) * stay unencoded:
const encoded = encodeURIComponent('hello world & goodbye');
// "hello%20world%20%26%20goodbye"
const decoded = decodeURIComponent(encoded);
// "hello world & goodbye"Python with urllib.parse.quote
CPython quote never encodes A–Z a–z 0–9 _ . - ~. Default safe='/' also leaves slashes, so quote('hello/world') stays hello/world while this page's Encode component writes hello%2Fworld. Pass safe="-_.!~*'()" to match encodeURIComponent. Avoid quote_plus — it writes + for spaces:
from urllib.parse import quote, unquote
encoded = quote('hello world & goodbye', safe="-_.!~*'()")
# 'hello%20world%20%26%20goodbye'
decoded = unquote(encoded)
# 'hello world & goodbye'Non-ASCII text follows the same UTF-8 path: café encodes to caf%C3%A9 in Node, CPython, and this page. quote_plus('hello world') writes hello+world — use URLSearchParams for that form-style encoding.
Percent-encoding in the shell
There is no POSIX percent-encoder. jq 1.7 @uri percent-encodes UTF-8 bytes and writes %20 for spaces — the same RFC 3986 style this page's Encode component uses for spaces, slashes, and &. It is not Encode URI (that leaves :/?#&= unencoded). jq leaves RFC 3986 unreserved characters (A–Z a–z 0–9 - _ . ~) unencoded. It encodes ! ' ( ) * as %21 %27 %28 %29 %2A; this page's encodeURIComponent leaves those marks unencoded. jq is not POSIX.
jq @uri
Pass -R so the input is a string — without it, jq 1.7 errors jq: parse error: Invalid numeric literal at line 1, column 6 on this sentence. -r writes the encoded string without extra quotes (without -r the same command writes a JSON string). -s slurps a trailing newline as %0A; -R without -s treats that newline as the line terminator. Use printf '%s' or jq -n --arg, not echo with -s:
printf '%s' 'hello world & goodbye' | jq -Rr @uri # hello%20world%20%26%20goodbye printf '%s' 'café' | jq -Rr @uri # caf%C3%A9 printf '%s' "hello!'()*" | jq -Rr @uri # hello%21%27%28%29%2A jq -nr --arg s 'hello/world' '$s|@uri' # hello%2Fworld printf '%s' \ 'https://example.com/search?q=hello world&category=news' \ | jq -Rr @uri # https%3A%2F%2Fexample.com%2Fsearch%3Fq%3Dhello%20world%26category%3Dnews
curl --data-urlencode
curl 8.5 --data-urlencode is application/x-www-form-urlencoded: spaces become +, not %20. That is the URLSearchParams convention, not this page. Hex digits may be lowercase (%2b for +); this page and jq write uppercase %2B. @- reads stdin as the value with no field name. -w '%{url_effective}' prints the encoded URL; the host is only a placeholder:
printf '%s' 'hello world & goodbye' \
| curl -s -G --data-urlencode @- \
-o /dev/null -w '%{url_effective}\n' \
https://example.invalid/
# https://example.invalid/?hello+world+%26+goodbye
curl -s -G --data-urlencode 'q=hello world & goodbye' \
-o /dev/null -w '%{url_effective}\n' \
https://example.invalid/
# https://example.invalid/?q=hello+world+%26+goodbyejq 1.7 has no @urid — that name errors urid is not a valid format. Decode with the Python unquote snippet above, or this page's Decode component. decodeURIComponent and unquote leave + as a plus; unquote_plus turns it into a space. @html writes HTML entities, not percent-encoding. CPython quote(..., safe='') encodes ! ' ( ) * the same way as jq; the snippet above passes safe="-_.!~*'()" to match this page. Already-encoded %20 becomes %2520 in jq and encodeURIComponent — do not pipe output through @uri twice.
FAQ
- Does this tool upload my text?
- No. All encoding and decoding runs entirely in your browser using JavaScript. Your URLs and text are never sent to a server.
- What is the difference between encodeURI and encodeURIComponent?
- encodeURI is for encoding a complete URL while preserving its structure — it leaves reserved characters like : / ? # & = intact. encodeURIComponent is for encoding a single value (like a query parameter) and encodes all special characters so the value is safe to embed in a URL.
- Why does this tool use %20 for spaces instead of +?
- encodeURI and encodeURIComponent follow RFC 3986, which uses %20 for spaces. The + notation for spaces is specific to application/x-www-form-urlencoded (HTML form submissions). Use our URLSearchParams tool if you need form-style encoding with + for spaces.
- Which characters are NOT encoded by encodeURIComponent?
- encodeURIComponent leaves these characters unencoded: A-Z a-z 0-9 - _ . ! ~ * ' ( ). This follows ECMA-262. All other characters are percent-encoded as UTF-8 bytes.
- Why did decoding fail with an error?
- decodeURI and decodeURIComponent throw an error when they encounter a malformed percent sequence — for example, a lone % sign or %XX where XX is not valid hexadecimal. Check your input for incomplete escape sequences.
- Does encoding handle Unicode characters like emoji?
- Yes. Both functions encode non-ASCII characters as their UTF-8 byte sequences. For example, é (U+00E9) becomes %C3%A9. Emoji and other multi-byte characters are encoded correctly.
Related guides
- URLSearchParams vs encodeURIComponent: Form vs Percent-Encoding
- WHATWG new URL vs encodeURI: Punycode vs Percent-Encoding
- Punycode vs IDNA: RFC 3492 and UTS #46
Related tools
- URLSearchParams — Build query strings with form-style encoding (+ for spaces)
- URL Parser — Parse URLs into their components
- Base64 Encoder — Encode binary data as ASCII text
- HTML Encoder — Escape HTML special characters