URL Encoder / Decoder

Encode, decode and transform URLs and query strings. Fully client-side.

Result will appear here...

Output is for reference only.

Percent-encode and decode URL components, with the encodeURI versus encodeURIComponent distinction that breaks more redirects than any other mistake.

Two different encoders

encodeURIComponent escapes everything except the unreserved characters, including slash, colon and question mark. That makes it correct for a single parameter value and wrong for a whole URL, because it destroys the separators that give the URL its structure.

encodeURI leaves the reserved characters that form URL syntax intact and escapes only what would break parsing. That makes it correct for a whole URL and wrong for a parameter value, because a slash inside a parameter would then leak into the path.

The rule of thumb: encode each parameter value with encodeURIComponent, then assemble the URL yourself.

Space is plus or percent-twenty

In a query string, a literal plus sign historically means space, following form-encoding conventions. Percent-encoding represents space as %20. Both decode to a space in most query parsers, but a plus inside a path segment stays a plus.

This is why a search term with a space sometimes arrives with a plus and sometimes with %20, and why encoding an already-encoded string double-escapes it into %2520. If a URL looks like it has been encoded twice, it has.

Unicode and reserved characters

Non-ASCII characters must be encoded as UTF-8 bytes before percent-escaping. A Chinese character becomes three percent-escaped bytes. Decoding those bytes with the wrong charset produces mojibake, which is the classic symptom of a page served without a charset declaration.

Characters that are legal but risky — quotes, angle brackets, backticks, spaces — should always be encoded in user-supplied input, since they are the building blocks of injection attacks when the value reaches HTML or a header.

Frequently asked questions

Why does my URL break after encoding?
You probably ran encodeURIComponent on the whole URL, which escaped the colon and slashes. Encode the parameters only.
Should I decode before or after splitting the query string?
Split first, then decode each value. Decoding first can turn an encoded ampersand inside a value into a real separator and cut the value in half.
Is my input sent anywhere?
No. Encoding and decoding use built-in browser functions on data already in the page.