How to URL-encode a string
- Type or paste the text into Text or URL. The output updates as you type.
- Choose the mode under Encode:
- Component (encodeURIComponent) for one query value, form field or path segment.
- Full URL (encodeURI) for a complete URL that has spaces or non-ASCII characters in it.
- Form data (space as +) for
application/x-www-form-urlencodedbodies and query strings built the way HTML forms do it. - Every character to percent-encode all bytes, letters included, for testing decoders.
- Leave Charset on UTF-8 unless the receiving system expects a legacy encoding.
- Tick Each line separately to encode a list of values in one go, then Copy output. Swap sends the result to the decoder to check the round trip.
A full URL in the input is also split into scheme, host, path, each query parameter and the fragment, in a table under the panes.
encodeURIComponent vs encodeURI vs form encoding
The same input, a b&c=d/é?#+, in the three common styles:
| Mode | Output | Use for |
|---|---|---|
Component (encodeURIComponent) | a%20b%26c%3Dd%2F%C3%A9%3F%23%2B | a single value inside a URL |
Full URL (encodeURI) | a%20b&c=d/%C3%A9?#+ | a whole URL that is already structured correctly |
Form data (URLSearchParams) | a+b%26c%3Dd%2F%C3%A9%3F%23%2B | HTML form posts, many query string libraries |
Component leaves only A–Z a–z 0–9 - _ . ! ~ * ' ( ) unescaped. Full URL also keeps ; / ? : @ & = + $ , #, the characters that give a URL its structure, so it cannot protect a value that contains them. Form data keeps only letters, digits and - _ . *, and writes spaces as +.
The classic bug is building a URL with Full URL encoding: ?q=C++ & Go keeps the + and &, and the server receives q=C plus a stray parameter. Encode the value with Component instead: ?q=C%2B%2B%20%26%20Go.
Spaces, plus signs and other troublemakers
| Character | Encoded | Why it matters |
|---|---|---|
| space | %20 or + | + only means space in query strings and form bodies |
+ | %2B | unencoded, many servers turn it into a space: +49 30 1234567 becomes 49 30 1234567 |
& | %26 | starts a new query parameter |
= | %3D | separates name and value; standard Base64 ends with it |
/ | %2F | splits path segments; some servers reject %2F in paths |
# | %23 | starts the fragment, which is never sent to the server |
% | %25 | must be encoded itself, or the decoder reads a broken escape |
€ | %E2%82%AC | three UTF-8 bytes, three escapes |
Base64 in a URL is a common case of the +, / and = problem. Either percent-encode it as a component or switch to Base64URL, which avoids those characters.
Non-UTF-8 charsets
Percent-encoding works on bytes, so the charset decides the result. é is %C3%A9 in UTF-8 and %E9 in Windows-1252 or ISO-8859-1. Modern browsers and APIs use UTF-8, but older PHP applications, some payment gateways and legacy intranet systems still expect Latin-1 or Windows-1252, and Japanese sites sometimes Shift_JIS. Choose the charset under Charset to match. A character that does not exist in the chosen charset cannot be represented, so check the output for those.
URL encoding in code
encodeURIComponent("a b&c") // "a%20b%26c"
new URLSearchParams({ q: "C++ & Go" }).toString() // "q=C%2B%2B+%26+Go"
from urllib.parse import quote, quote_plus, urlencode
quote("/files/a b.txt") # '/files/a%20b.txt' (keeps / by default)
quote("/files/a b.txt", safe="") # '%2Ffiles%2Fa%20b.txt'
quote_plus("a b&c") # 'a+b%26c'
urlencode({"q": "C++ & Go"}) # 'q=C%2B%2B+%26+Go'
Python’s quote keeps / unless you pass safe="", a frequent surprise when encoding a value. Elsewhere: PHP’s rawurlencode gives %20 and urlencode gives +; Java’s URLEncoder.encode is form encoding with +; Go has url.PathEscape (%20) and url.QueryEscape (+). encodeURIComponent leaves ! ' ( ) * alone; for strict RFC 3986 output, replace them afterwards:
const strict = s => encodeURIComponent(s).replace(/[!'()*]/g,
c => "%" + c.charCodeAt(0).toString(16).toUpperCase());
More on the JavaScript side is on the JavaScript Base64 page. To reverse any of this, use the URL decoder.
FAQ
What is URL encoding?
URL encoding, or percent-encoding, replaces characters that are not allowed or have a special meaning in a URL with % and two hex digits of each byte. A space becomes %20, & becomes %26, and é in UTF-8 becomes %C3%A9.
How do I encode a space in a URL: %20 or +?
%20 works everywhere. + means a space only in query strings and form bodies that follow the form-encoding convention; in a path it is a literal plus. When unsure, use %20.
Should I URL-encode the whole URL?
No, encode each value before you insert it. Encoding a whole URL with Component also escapes :, /, ? and &, which breaks it. Full URL mode keeps those structural characters and only fixes spaces and non-ASCII text.
Why does my encoded string contain %25?
%25 is an encoded percent sign, which means the input was already encoded and got encoded a second time: a%20b turns into a%2520b. Encode raw text exactly once.
Uppercase or lowercase hex in percent-encoding?
RFC 3986 treats %2F and %2f as the same and recommends uppercase. Tick Lowercase hex only when matching a system that produces lowercase, for example when comparing signatures.