Skip to content
Developer

URL & HTML Entity Encoder

Encode and decode URLs and HTML entities. The two URL encoders are shown together, because picking the wrong one is a real bug rather than a matter of taste.

Press Esc to clear

URL encoding

encodeURIComponent — for a value

Use this for anything going inside a URL, such as a query parameter.

encodeURI — for a whole URL

Leaves / ? & = intact, so only use it on a complete URL.

Decoded

HTML entities

Escaped

Escaped, including non-ASCII

Decoded

About the URL & HTML Entity Encoder

There are two URL encoders in JavaScript and choosing between them is not a style decision. encodeURI leaves alone the characters that structure a URL — the slashes, the question mark, the ampersands — because it is meant for encoding a whole URL. encodeURIComponent escapes those characters, because it is meant for a single value going inside one.

Using the wrong one produces a bug that hides until the data changes. Encoding a query parameter with encodeURI looks perfectly fine until a value contains an ampersand, at which point the parameter silently splits into two and the second half is discarded by the server. This tool shows both outputs at once so the difference is visible rather than something you have to remember.

HTML entity encoding solves the related problem of putting arbitrary text into a page without it being read as markup. The order of operations matters: the ampersand has to be escaped first, or every entity produced afterwards gets double-encoded and your page fills up with < where you expected a less-than sign.

Decoding handles all three entity forms — named like ©, decimal like ©, and hexadecimal like © — and leaves anything it does not recognise untouched instead of deleting it. A percent-escape that is not followed by two valid hex digits produces a clear message rather than a thrown exception.

Everything runs in your browser.

Frequently asked questions

Which URL encoder should I use?

encodeURIComponent for a value going inside a URL, such as a query parameter. encodeURI only for an entire URL you want to leave structurally intact. Using encodeURI on a value breaks as soon as the value contains an ampersand.

Why does the ampersand have to be escaped first?

Because every other entity starts with one. Escape the less-than sign first and its resulting < gets its ampersand escaped afterwards, producing < on the page instead of a bracket.

Does it handle numeric HTML entities?

Yes — named, decimal and hexadecimal forms all decode. Unrecognised entities are left as they are rather than being silently removed.