Ennadia
Text & Data

HTML Entity Encoder

Escape and unescape HTML entities with a click.

  • Local by default
  • No signup
  • AI is opt-in

Output

 

Decoding recognises common named entities plus decimal and hex references; unknown names are left untouched. This is a text transform, not an HTML sanitizer.

Encode text so it can sit safely inside HTML, or decode a page of entities back into readable characters. The decoder handles common named entities plus decimal and hexadecimal references, and it never touches the DOM, so nothing is executed.

What an HTML entity actually is

An entity is a short sequence that stands for a character. Named entities begin with an ampersand and a name, such as < for a less-than sign. Numeric references use a code point instead: < in decimal or < in hex. Both forms are resolved by the browser before the markup is rendered.

Because the ampersand starts every entity, a literal ampersand must itself be escaped. That single rule explains most double-encoding bugs: escaping text twice turns & into &, which displays as the four characters “&” instead of “&”.

Where escaping is required — and where it is not

  1. HTML text nodes: escape & and <. A bare > is usually harmless but is escaped for consistency.
  2. Quoted attributes: escape the quote character that delimits the value, plus &. Double quotes are the default here.
  3. Unquoted attributes: avoid them; spaces, tabs and several punctuation marks break the value. Escaping alone does not make an unquoted attribute safe.
  4. JavaScript strings: HTML entities are not interpreted. Use JSON encoding or the escape rules of the language instead.
  5. URLs: use percent-encoding, not HTML entities. The two encodings look similar but are decoded at different stages.
  6. CSS: use CSS escapes. HTML entities are not resolved in style sheets.

The encoder therefore escapes only the five characters that matter in HTML text and quoted attributes: ampersand, less-than, greater-than, double quote and apostrophe. Escaping everything is legal but makes the source unreadable and inflates the payload.

Named versus numeric entities

Named entities are readable: &mdash; says more than &#8212;. But names depend on the HTML entity table, and only a few dozen are memorable. Numeric references work for any Unicode code point, including characters that have no name at all, and they do not depend on the document encoding once the file is decoded.

This decoder knows a practical subset of names: punctuation, currency, arrows, maths symbols, Greek letters and common accented Latin letters. Anything outside that table is left exactly as written, which is safer than guessing. Numeric references are always resolved when the code point is valid and is not a lone surrogate.

A missing semicolon is not repaired. Browsers sometimes accept &copy without a semicolon, but that behaviour is error-prone, so this tool only decodes well-formed references.

Double encoding and the way out

Double encoding happens when a template system escapes a value that was already escaped, or when data is escaped once on write and again on read. The visible symptom is text that shows entity syntax instead of the character it represents. The fix is to escape exactly once, at the boundary where text becomes markup, and to store unescaped text everywhere else.

Decoding once reverses one layer, not all layers. That is deliberate: running the decoder until the text stops changing would also destroy legitimate content that happens to look like an entity, such as documentation about HTML itself.

Decoding is not sanitizing

This tool converts text to text. It does not parse HTML, remove tags, strip event handler attributes or decide whether a string is safe to inject into a page. A decoded string may contain assumptions that were safe only in its encoded form, so inserting it with innerHTML can still execute script.

Use a context-aware sanitizer or a framework that escapes by default when you build markup. Reserve this page for inspecting payloads, migrating content between systems and debugging templates.

Choosing an encoding strategy

  1. Store the original characters; escape at render time.
  2. Escape quotes as well as angle brackets when you write attribute values.
  3. Escape non-ASCII only when the downstream system cannot handle UTF-8, for example some legacy email or SMS gateways.
  4. Prefer numeric references for characters outside the named table, and hex for code points above U+FFFF such as emoji.
  5. Do not use HTML entities in JSON, URLs, shells or SQL. Each format has its own escaping rules.

Frequently asked questions

Does decoding &amp;amp;lt; produce < or &lt;?

It produces &lt;. The decoder makes a single pass, so one layer of encoding is removed. Run the decode again if you genuinely need to peel off a second layer.

Is this an HTML sanitizer?

No. It never parses or evaluates markup and has no allow-list of tags. It only replaces entity syntax with the characters they represent. Sanitizing requires a dedicated parser such as DOMPurify on the client or a server-side HTML sanitizer.

Why is an apostrophe encoded as &amp;#39; instead of &amp;apos;?

The numeric form works in HTML and XML alike, while &amp;apos; is an HTML5 addition. Both are valid in modern browsers; the numeric form is the more portable choice.

Can it decode emoji and other characters above U+FFFF?

Yes, when they are written as a numeric reference with the correct code point, for example &amp;#x1F600;. Named entities for emoji are not included in the table.

Why did one entity remain unchanged?

Either the name is outside the built-in table, or the numeric reference is malformed, zero, above U+10FFFF, or a surrogate value. Those cases are left as-is on purpose rather than replaced with a question mark.

Is the text uploaded anywhere?

No. Encoding and decoding run with plain string operations in your browser. Nothing is sent over the network and the page has no analytics on the input.