HTML Entity Encoder & Decoder

Escape text for HTML and decode entities back, with the escaping rule chosen for where the value is actually going.

Everything runs in your browser. Context-aware escaping is the core defence for text in HTML, but it does not cover values going into script blocks, style blocks or URL attributes.

What It Does

Converts text into HTML entities so it displays as data rather than being parsed as markup, and converts entities back to readable characters. The part that matters is context. In element text only the ampersand and angle brackets can break out. Inside a quoted attribute the quote character is the dangerous one, because a value containing it ends the attribute early and everything after is read as markup — which is the difference between text being shown and text becoming executable. So the tool asks where the value is going rather than applying one rule to everything. It escapes the ampersand first, which is what stops its own output being re-escaped into the < that renders as literal text, and it flags that double-encoding when it finds it in your input.

When to Use It

  • User-supplied text is going into a page and needs escaping so it cannot break out of its element or attribute.
  • A code sample needs to appear literally in documentation rather than being rendered as markup.
  • Text arrived already escaped from an API or a database and you need to read what it actually says.
  • Something renders as < on a page and you need to confirm it was double-encoded.
  • An email template needs pure ASCII because the client mangles anything else.

Worked Examples

<script>alert("hi")</script>

The canonical case. Every angle bracket becomes an entity so the browser shows the text instead of running it — and in attribute context the quotes are escaped too, since a quote would otherwise end the attribute and let the rest be parsed as markup.

Tom & Jerry's <b>Show</b>

Three different characters needing three different treatments. The ampersand goes first — escaping it later would re-escape the entities just created and produce the &amp;lt; that renders literally.

&lt;p&gt;Already escaped&lt;/p&gt;

Text that has already been through an escaper once. Decoding gives back the original markup; encoding it again produces the double-encoded form, which the tool flags rather than quietly handing you.

Features

Context-aware escaping for element text or attributes
Ampersand escaped first to prevent double-encoding
Double-encoding detected and flagged
Named or numeric entity output
Hexadecimal references available
Optional escaping of all non-ASCII characters
Decoding of named
decimal and hex references
Unknown entities left intact rather than dropped
Breakdown of exactly which characters were escaped
Runs entirely in your browser

How to Use

1. Choose a direction — encode or decode. 2. Paste your text or your entities. 3. For encoding, pick the context: element text, or inside an attribute. 4. Read the breakdown to see exactly which characters were escaped and why. 5. Copy the result, or swap to send it back the other way.

Common Mistakes

  • Using one escaping rule everywhere. A value safe in element text can still break out of an attribute, because the quote character matters there and the angle brackets matter less.
  • Escaping the ampersand last. It re-escapes the entities just produced, giving &amp;lt; which renders as literal text rather than as the character.
  • Relying on HTML escaping inside a href or a script block. A value of javascript:alert(1) contains nothing HTML escaping would touch — those contexts need their own handling.
  • Using &apos; for an apostrophe. It is XML and HTML5 only, so older parsers and some email clients show it as literal text — the numeric form works everywhere.
  • Escaping non-ASCII by default. Modern UTF-8 pages handle accents and emoji natively, and escaping them just makes the source far harder to read.

Frequently Asked Questions

Explore related topics

#Security #HTML #Escape #Entity