Skip to content
Reembun
HTML encode/decode icon
Developer

HTML encoder and decoder

Escape the five characters that break HTML, or decode any named or numeric entity back to plain text.

Ready. Runs locally on your device.

Your files stay on your device. The tool works directly in your browser, using your device to process your files. Nothing is sent to our servers, and we never receive, store, or see your files or figures.

Share

Share this page

Share result

Your results

Use the tool above first. Whatever it works out shows up here, ready to copy or share.

Cite

Cite this page

Reembun. (2026, July 28). HTML encoder and decoder. https://reembun.com/html-encoder
Pick a style, then copy the reference. The access date is today.

How to use it

  1. Pick a direction

    Encode turns characters into HTML entities. Decode turns entities back into the characters they stand for.

  2. Paste the markup or text

    Encoding is what lets you show a tag on a page instead of running it, which is also what stops user text becoming an injection.

  3. Decide how far to go

    Also escape non-ASCII converts accented letters and symbols into numeric entities, for templates that cannot be trusted to stay UTF-8.

  4. Copy the output

    Copy takes the converted text, ready to paste into a template or a CMS field.

The five characters

CharacterNamedNumericWhy it matters
&&&Starts every other entity
<&lt;&#60;Starts a tag
>&gt;&#62;Ends a tag
"&quot;&#34;Ends a double-quoted attribute
'&#39;&#39;Ends a single-quoted attribute

Note that ' has no widely-supported named form in HTML 4, since &apos; is XML and HTML5 only, which is why &#39; is the safe choice.

Order matters

The ampersand must be escaped first. Escaping < to &lt; and then escaping ampersands turns it into &amp;lt;, which displays as the literal text &lt; rather than a less-than sign.

Wrong:  < → &lt; → &amp;lt;   displays as "&lt;"
Right:  & first, then the rest

Double-encoding is the most common bug in hand-rolled escaping, and it usually appears as visible entity text on a page.

Escaping is context-dependent

HTML escaping protects HTML contexts. It does nothing for the others, and using it in the wrong place gives false confidence.

ContextCorrect encoding
HTML textHTML entities
HTML attribute valueHTML entities, quoted attribute
URL parameterPercent encoding
JavaScript stringJavaScript string escaping
CSS valueCSS escaping
Inside a <script> blockDo not interpolate at all

A value that is HTML-escaped and then placed inside an onclick attribute is still exploitable, because the browser decodes the entities before the JavaScript parser sees the result.

The reliable defence is a template engine that escapes automatically and knows the context. Every modern framework does this, and the vulnerabilities that remain are almost always in the places where developers deliberately bypassed it.

Decoding

Decoding here uses the browser’s HTML parser rather than a lookup table. The specification defines more than 2,000 named references, including obscure ones like &hellip;, &nbsp;, &mdash; and a long tail of mathematical and Greek symbols.

The parsing happens by assigning to a textarea element’s innerHTML and reading back its value. That element type is used specifically because its content model is raw text, so markup inside it parses but never executes, so decoding a string containing a script tag is safe.

Non-ASCII characters

The “also escape non-ASCII” option converts everything outside printable ASCII into numeric references:

Café  →  Caf&#233;
日本   →  &#26085;&#26412;
🎉     →  &#127881;

This is rarely necessary with a correct <meta charset="utf-8"> declaration, which every modern page should have. It remains useful when output lands somewhere with an unknown or unreliable charset: legacy email templates, some CMS fields, and systems that mangle bytes above 127.

Common questions

Which characters actually need escaping?

Five: & < > " and '. The ampersand is first because it starts every other entity, so it must be escaped before the rest or you get double-encoding. The two quote characters only matter inside attribute values, but escaping them unconditionally is simpler and harmless.

Is escaping HTML enough to prevent XSS?

No. It is necessary in HTML text and attribute contexts and insufficient everywhere else. Text going into a JavaScript string, a URL, a CSS value or an event handler attribute each needs a different encoding. Context-aware output encoding, ideally from your template engine, is the actual defence.

Why does decoding here handle every named entity?

Because it uses the browser's own HTML parser rather than a lookup table. There are over 2,000 named references in the HTML specification, and a hand-written map inevitably misses some. The parsing is done in a textarea, which parses markup without executing anything.

What is the difference between named and numeric entities?

Named entities like &amp; are readable; numeric ones like &#38; work for any character without needing a name. Named entities outside the core five are inconsistently supported in XML and some older parsers, so numeric references are the safer choice for anything non-ASCII.

Last reviewed