URL Encoder / Decoder
Encode or decode text for URLs and query strings, and see exactly which characters turn into which percent codes.
encodeURIComponent(), which escapes separators such as &, = and /. That is the right choice for a single value, not for a complete URL.
Encoded or decoded output
Decoding reverses the percent codes and rebuilds the original UTF-8 text.
Percent-encoding quick reference
| Character | Code | Role in a URL |
|---|---|---|
| Space | %20 | Not allowed raw in a URI |
& | %26 | Separates query parameters |
= | %3D | Separates a name from its value |
? | %3F | Starts the query string |
# | %23 | Starts the fragment |
/ | %2F | Separates path segments |
+ | %2B | Literal plus in a value |
% | %25 | Introduces every escape |
Percent-encoding turns characters into safe bytes
A URL is a structured text format with reserved separators. Encoding protects a value so that its content cannot be mistaken for that structure.
What percent-encoding does
The URI standard divides characters into two groups. Unreserved characters are always safe: letters A-Z and a-z, digits 0-9,
hyphen, period, underscore and tilde. Reserved characters have a syntactic meaning, such as / in a path or & between query parameters.
Everything else must be escaped before it can travel inside a URL.
An escape is a percent sign followed by two hexadecimal digits that represent one byte. A space is byte 32 in ASCII, which is 20 in hex, so a space becomes %20.
The two digits are case-insensitive: %2f and %2F are the same escape, although uppercase is the common convention.
Encoding is not encryption and it is not compression. It is a reversible transport rule. Anyone can decode a URL, and decoding does not require a key.
encodeURIComponent vs encodeURI
JavaScript ships two functions with similar names and very different jobs. encodeURIComponent() escapes everything except the unreserved set plus a few sub-delimiters that are
harmless in a value: ! ~ * ' ( ). It is designed for one parameter value, one path segment or one fragment.
encodeURI() keeps the characters that give a URL its structure, including ; , / ? : @ & = + $ #. It is designed for a complete URL that is already assembled
and only contains stray spaces or non-ASCII text.
| Input | encodeURIComponent() | encodeURI() |
|---|---|---|
a b | a%20b | a%20b |
a&b=c | a%26b%3Dc | a&b=c |
/docs/a b | %2Fdocs%2Fa%20b | /docs/a%20b |
café | caf%C3%A9 | caf%C3%A9 |
The rule of thumb is simple: encode the pieces, then join them with the separators you wrote yourself. Running encodeURIComponent() on a whole URL
turns https://example.com/a into https%3A%2F%2Fexample.com%2Fa, which is no longer a URL but a single path segment.
Query strings, paths and form data
Each part of a URL has its own rules. The scheme and host are not percent-encoded. The path is a sequence of segments separated by /. The query begins after ?
and carries name-value pairs separated by & and joined by =. The fragment begins after # and is handled by the browser, not sent to the server.
HTML forms add a wrinkle. When a form is submitted with the default application/x-www-form-urlencoded type, spaces are sent as + rather than %20.
A query parser that follows that convention turns + back into a space, which is why a literal plus sign must be encoded as %2B.
decodeURIComponent() does not convert + to a space, so a value read from a form can look wrong if the plus is not handled separately.
A query value is everything after the first = and before the next &. If the value itself contains &, it must be encoded as %26,
otherwise the server sees an extra parameter. In JavaScript, URLSearchParams applies the form rules for you: it escapes the values and writes a space as +.
Building the same string by hand with encodeURIComponent() writes a space as %20. Both forms are valid query strings, but the server must decode them with matching rules.
Unicode, UTF-8 and multi-byte escapes
Percent-encoding works on bytes, not on characters. A non-ASCII character is first encoded as UTF-8, then each byte becomes its own escape. That is why accented letters and emoji produce several escapes instead of one.
| Text | UTF-8 bytes | Percent-encoded |
|---|---|---|
é | C3 A9 | %C3%A9 |
ñ | C3 B1 | %C3%B1 |
中 | E4 B8 AD | %E4%B8%AD |
😀 | F0 9F 98 80 | %F0%9F%98%80 |
Decoding a byte sequence with the wrong character set produces mojibake, the familiar sequence of accented gibberish. The escapes themselves do not declare an encoding;
the receiving application has to know that UTF-8 was used. Modern web pages declare it with <meta charset="utf-8">, and JSON uses UTF-8 by default.
Decoding safely and avoiding double encoding
Decoding is strict. A percent sign that is not followed by two hexadecimal digits is invalid, and JavaScript throws a URIError in that case.
The tool reports the error instead of returning a partial string, because a silent partial decode hides the real problem.
Double encoding is the most common accident. If a b is encoded to a%20b and then encoded again, the percent sign is escaped to %25 and the result is
a%2520b. The server decodes it once and still sees a%20b, so the visible value keeps the escape instead of the space.
encodeURIComponent('a b') → a%20b
encodeURIComponent('a%20b') → a%2520b
decodeURIComponent('a%2520b') → a%20b
Decide once where encoding happens. A common pattern is to encode when the URL is built and never again in the HTTP client, unless that client documents that it encodes the URL itself.
Common URL encoding errors
| Error | Symptom | Fix |
|---|---|---|
| Encoding the whole URL | https%3A%2F%2F... appears in the address bar | Encode only the values |
| Double encoding | %2520 or %2526 in the request | Encode once, at the boundary |
Leaving & unencoded in a value | The server receives an extra parameter | Escape it as %26 |
Assuming + means space everywhere | A literal plus disappears or becomes a space | Use %2B for a literal plus |
| Truncated escape | URIError: URI malformed | Keep all six characters of %C3%A9 |
| Unencoded non-ASCII | Works in one browser, breaks in another | Encode to UTF-8 percent escapes |
The URI standard does not define a maximum length. Practical limits come from browsers, proxies and servers, and they differ. Very long query strings are usually a sign that the data belongs in a request body rather than in the URL.
Related Developer & Security Tools
| Tool | What does it do? | Action |
|---|---|---|
| Base64 Encoder & Decoder | Encode text to Base64 or decode a Base64 string back to plain text. | Base64 Codec → |
| Hash Generator | Create MD5, SHA-1, SHA-256 and SHA-512 hashes from text. | Hash Maker → |
| UUID Generator | Generate random UUID v4 values, one or many at a time. | UUID Maker → |
| Password Generator | Build strong random passwords with length and character options. | Password Maker → |
| Regex Tester | Test a regular expression against sample text and inspect the matches. | Regex Test → |
| JWT Decoder | Decode a JWT header and payload locally, without sending the token anywhere. | JWT Decode → |
Frequently Asked Questions
%20 and & becomes %26.encodeURIComponent() for a single value, path segment or parameter, because it escapes separators such as & and =. Use encodeURI() only for a complete URL whose structure is already correct.application/x-www-form-urlencoded, where + represents a space. Parsers that follow that convention decode it as a space. To keep a literal plus, encode it as %2B.é takes two bytes in UTF-8, C3 and A9, so it becomes %C3%A9. Four-byte characters such as emoji produce four escapes.
Rate this Tool
Based on 0 user ratings.