URL Encoder / Decoder
Convert special characters to percent-encoding (e.g., space becomes %20) and back.
What is URL encoding?
URL encoding, also called percent encoding, replaces characters that have special meaning in a URL - or that cannot appear in one at all - with a percent sign followed by their hexadecimal byte value. A space becomes %20, an ampersand becomes %26.
It exists because URLs have a restricted character set and a grammar in which certain characters are structural. An unencoded ampersand inside a query value would be read as the start of a new parameter, silently truncating your data.
Key takeaways
- Percent encoding replaces a character with % followed by its hex byte value.
- A space becomes %20, or + in the older form-encoded style.
- encodeURIComponent is for individual values; encodeURI is for whole URLs.
- Using the wrong one of those two is the most common URL encoding bug.
- Non-ASCII characters are encoded per UTF-8 byte, so one character can become several triplets.
Reserved characters
| Character | Encoded | Structural meaning in a URL |
|---|---|---|
| space | %20 | Not permitted at all |
| ! | %21 | Sub-delimiter |
| # | %23 | Starts the fragment |
| $ | %24 | Sub-delimiter |
| & | %26 | Separates query parameters |
| ' | %27 | Sub-delimiter |
| + | %2B | Means a space in form encoding |
| , | %2C | Sub-delimiter |
| / | %2F | Separates path segments |
| : | %3A | Separates scheme and port |
| = | %3D | Separates parameter name and value |
| ? | %3F | Starts the query string |
| @ | %40 | Separates userinfo from host |
Unreserved characters - A-Z, a-z, 0-9, hyphen, underscore, full stop and tilde - never need encoding. The percent-encoded forms above are what each character becomes when it must be escaped. Note that this tool, like JavaScript's encodeURIComponent, leaves ! ' ( ) and * unencoded, because they are rarely a problem in practice; encode them by hand if a strict RFC 3986 consumer needs it.
encodeURI versus encodeURIComponent
This is the distinction that causes most URL encoding bugs.
| encodeURI | encodeURIComponent | |
|---|---|---|
| Purpose | Encode a complete URL | Encode one value within a URL |
| Leaves : / ? # & = alone? | Yes | No - encodes them |
| Use for | Tidying a whole URL | Query values, path segments, form data |
| Encodes a space | Yes, as %20 | Yes, as %20 |
"/search?q=" + encodeURI("cats & dogs")
gives /search?q=cats%20&%20dogs (the & splits the parameter)
Right:
"/search?q=" + encodeURIComponent("cats & dogs")
gives /search?q=cats%20%26%20dogs
The plus sign problem
There are two conventions for encoding a space, and they are not compatible:
- %20 - the standard percent encoding, valid anywhere in a URL.
- + - the older application/x-www-form-urlencoded convention, used in HTML form submissions.
This means a literal plus sign in a query value must be encoded as %2B, or it will be decoded as a space. Email addresses using plus addressing - user+tag@example.com - break constantly for exactly this reason: the plus arrives at the server as a space.
Non-ASCII characters
Characters outside ASCII are encoded byte by byte after conversion to UTF-8, so a single character can become several percent triplets.
| Character | UTF-8 bytes | Encoded |
|---|---|---|
| é | 2 | %C3%A9 |
| 日 | 3 | %E6%97%A5 |
| 😀 | 4 | %F0%9F%98%80 |
| café | 5 total | caf%C3%A9 |
This is why an encoded URL containing non-English text looks so much longer than the original.
Practical guidance
- Never encode twice. Double encoding turns %20 into %2520 and is a common bug when a value passes through several layers.
- Encode values, not separators. Build the URL structure first, then encode each value as you insert it.
- Use your platform's URL builder where one exists - URLSearchParams in JavaScript, or the equivalent in your language - rather than concatenating strings.
- Decode exactly once, and be wary of frameworks that decode automatically before your code sees the value.
- Watch for encoded slashes. Some servers reject or normalize %2F in a path, which breaks values containing slashes.
Frequently Asked Questions
What is URL encoding?
Also called percent encoding, it replaces characters that have special meaning in a URL, or that cannot appear in one, with a percent sign followed by their hexadecimal byte value. A space becomes %20 and an ampersand becomes %26.
What is the difference between encodeURI and encodeURIComponent?
encodeURI is for a complete URL and deliberately leaves structural characters such as colon, slash, question mark and ampersand alone. encodeURIComponent is for a single value and encodes those characters too. Using encodeURI on a query value is the most common URL encoding bug.
Which one should I use?
encodeURIComponent, almost always. If you are encoding something a user typed, a filename or an ID that will sit inside a URL, that is the right function. Only use encodeURI when you already have a complete URL and want to make it safe without destroying its structure.
Why does a plus sign become a space?
Because the older form-encoding convention uses plus to mean a space. A literal plus must be encoded as %2B. This is why email addresses using plus addressing break so often - the plus arrives at the server as a space.
Which characters need encoding?
The reserved characters that have structural meaning - space, ampersand, question mark, hash, slash, colon, equals, plus, at and several others. Letters, digits, hyphen, underscore, full stop and tilde are unreserved and never need encoding.
Why does one accented character become several percent codes?
Because encoding operates on UTF-8 bytes, not characters. An accented Latin letter is two bytes, a CJK character three, and an emoji four, so each produces that many percent triplets.
What is double encoding and why is it a problem?
It happens when an already-encoded value is encoded again, turning %20 into %2520. The receiving end decodes once and gets %20 as literal text rather than a space. It usually occurs when a value passes through several layers each applying encoding.
Can I encode a list of URLs or values at once?
Yes. Tick One per line (bulk) and paste one value per line. Each line is encoded or decoded on its own, so the list keeps its line breaks instead of them becoming %0A. If one line cannot be decoded, the output says which line, and the rest still convert.
Is my data sent anywhere?
No. Encoding and decoding happen entirely in your browser and nothing is transmitted or stored.