URL encoder and decoder
Percent encode and decode, both directions, with encodeURI and encodeURIComponent shown side by side so you can see exactly where they differ. That difference is usually the reason a URL broke. Free, no signup, and nothing leaves your browser.
encodeURIComponent
For one piece of a URL
https%3A%2F%2Fexample.com%2Fsearch%3Fq%3Dcaf%C3%A9%20%26%20cream%26page%3D2
Escapes everything except letters, digits and - _ . ! ~ * ' ( ). Use it for a single query parameter value, a path segment or a fragment, because it escapes the separators that would otherwise end the value early.
encodeURI
For a whole URL
https://example.com/search?q=caf%C3%A9%20&%20cream&page=2
Leaves the reserved characters ; / ? : @ & = + $ , # alone, because in a complete URL they are structure rather than data. Use it when you have an entire address that only needs its spaces and non ASCII characters escaped.
Form encoding
Spaces become plus
https%3A%2F%2Fexample.com%2Fsearch%3Fq%3Dcaf%C3%A9+%26+cream%26page%3D2
The application/x-www-form-urlencoded variant, which is what an HTML form submits and what most query strings use. Identical to encodeURIComponent except that a space becomes a plus sign rather than %20.
That input parses as a URL
- Scheme
- https
- Host
- example.com
- Path
- /search
- Query
- q = café cream = page = 2
The query values above are already decoded. Each one on its own is what encodeURIComponent belongs on.
Runs in your browser. The encoding happens in this tab. The URL, token or search query you paste is never uploaded, logged or stored.
encodeURI or encodeURIComponent
The two differ on exactly one thing: what they do with the reserved characters, the punctuation that gives a URL its shape. Those are ; / ? : @ & = + $ , and #.
encodeURI leaves them alone, because it assumes you handed it a complete address where a slash separates path segments and an ampersand separates parameters. It escapes spaces and non ASCII characters and nothing else.
encodeURIComponent escapes them, because it assumes you handed it one piece of data that has to survive being dropped inside a URL. A slash in a search term is part of the term, not a path separator, so it has to become %2F.
The rule that follows: encodeURIComponent for the values, encodeURI for the whole thing. Getting it backwards is the classic bug. A search for red & blue encoded with encodeURI keeps its ampersand, so the server sees a parameter q=red and a second parameter called blue, and the search silently runs on half the query.
Where the two disagree, character by character
| Character | encodeURI | encodeURIComponent | Form |
|---|---|---|---|
| space | %20 | %20 | + |
| / | / | %2F | %2F |
| ? | ? | %3F | %3F |
| & | & | %26 | %26 |
| = | = | %3D | %3D |
| # | # | %23 | %23 |
| : | : | %3A | %3A |
| + | + | %2B | %2B |
| @ | @ | %40 | %40 |
| é | %C3%A9 | %C3%A9 | %C3%A9 |
Everything outside that list behaves identically in both. Letters, digits and the characters - _ . ! ~ * ' ( ) pass through untouched, and anything non ASCII becomes its UTF-8 bytes written as percent escapes, which is why an accented e is two escapes and an emoji is four.
The plus sign problem
Percent encoding says a space is %20. The application/x-www-form-urlencoded format, which is what an HTML form submits and what most query strings use in practice, says a space is a plus sign. Both are correct in their own context, which is precisely why they cause trouble.
A plus sign inside a path segment is a literal plus. A plus sign inside a form encoded query value is a space. Decode with the wrong rule and you get spaces where a plus was meant, which quietly corrupts phone numbers, chemical formulae and anything else where the character matters. That is why form encoding is listed here as its own result rather than folded into the other two.
Frequently asked questions
- What is the difference between encodeURI and encodeURIComponent?
- encodeURIComponent escapes the reserved characters, so a slash becomes %2F and an ampersand becomes %26. encodeURI leaves those alone, because in a whole URL they are structure rather than data. Use encodeURIComponent for one query parameter value or path segment, and encodeURI for a complete address that only needs its spaces and non ASCII characters fixed.
- Which one should I use for a query string value?
- encodeURIComponent, every time. If the value contains an ampersand or an equals sign and you used encodeURI, those characters survive unescaped and the server reads them as the start of the next parameter, which truncates your value or invents one that was never sent.
- Why does a space sometimes become %20 and sometimes a plus sign?
- Both are correct, in different places. Percent encoding says %20. The application/x-www-form-urlencoded format, which HTML forms submit and most query strings use, says a plus sign. A plus in a path segment stays a literal plus, which is why decoding with the wrong rule turns plus signs into spaces that were never there.
- Is the encoding done on your server?
- No. It runs in your browser, so the URL, the token or the search query you paste stays on your device and is never uploaded or logged.
- Why did my decode fail with a malformed escape error?
- A percent sign has to be followed by exactly two hexadecimal digits, so a literal percent in text has to be written %25. A stray percent, as in a copied 100% figure, breaks decoding. The other cause is a multi byte character that was copied in half, which leaves valid looking escapes that do not spell out valid UTF-8.
- Does percent encoding hide anything?
- No. It is a formatting rule, not a security measure. Anyone can decode it in one step, so a token or an email address in a URL is exactly as readable after encoding as before.
Encoding rules are worth knowing once. Your syllabus is worth knowing properly.
FORKSAI turns your notes, slides and PDFs into flashcards and spaced repetition sessions, so the things you look up twice you eventually stop looking up.
The tool above stays free and needs no account.
More free tools
There are file and format tools too, such as image converter, compress image to size, favicon generator, and the full set is on the free tools hub.
Plan your next review session
Use the free student study kit to plan a week of revision, check flashcard quality, and record mistakes from practice questions.
Need a deck first? Turn a lecture PDF into editable flashcards, then follow the active recall guide to practise answering before revealing the back of each card.
Working toward an exam? Build a daily target with the exam study planner, protect the session with the Pomodoro study timer, or check your current result with the weighted GPA calculator.