HTML Entities

Web

Encode or decode HTML entities for safe rendering: named and numeric references, decimal and hex codes, ready to copy. Prevents XSS in templating output.

Encoded
Raw HTML
44 chars
Entities
85 chars

About HTML Entities

HTML entity encoding turns syntactically meaningful characters such as <, >, &, and " into safe forms like &lt;, &gt;, &amp;, and &quot;. So the browser will not parse them as tags or attributes, and keeps symbols like © or € rendering consistently across encodings. This tool converts between named entities, decimal (&#169;), and hexadecimal (&#xA9;) forms, and lets you choose to encode only the required characters or every non-ASCII character. Named and numeric entities differ in readability and coverage, and which to use follows the context. Named forms build on mnemonic words that a person recognises at a glance, but the set is limited and misses characters, while numeric forms use a code point to cover anything at the cost of readability. Use named forms in prose for maintainability and numeric ones for rare characters. The characters that must be escaped are a floor, not the whole rule. Angle brackets and ampersands must be escaped in text or they start a tag or an entity, and quotes need handling inside attribute values depending on which quote delimits the attribute. Judge escaping by position, treating text, attribute values and the quoting attribute separately rather than one blanket replacement. Double escaping is the most common mistake and its symptom is easily mistaken for the content itself. Escaping already-escaped content shows the entity characters literally on the page, where a symbol should appear and a string of characters instead. Escape once, at the write step, and never re-escape on read or re-render, or every pass adds another layer. Entity rules differ by context, which is why blanket replacement fails. Text content, attribute values, script and style bodies, and URL components each need different degrees of handling, and applying the strictest replacement everywhere can break structure that should survive. Choose the rule by the enclosing context rather than processing a whole block uniformly. Invisible characters and space entities are easily missed layout details. One entity denotes a non-breaking space that does not collapse with neighbouring whitespace and is used to keep a number with its unit or two words on one line, while other width-variant spaces render differently from an ordinary one. Identify which space is present before deciding how to replace it. Finally, correct interpretation depends on the encoding declaration, and without it you get mojibake rather than an error. An undeclared page is guessed at by the browser, so the same entities may display as different characters under different guesses and the symptom is unstable. Confirm the source encoding matches the page declaration before checking the entity spelling.

How It Works Internally

An entity spells one character using a sequence of others: named entities look up a table, numeric entities encode a code point, and decimal and hexadecimal forms are equivalent. When the trailing semicolon is missing the parser falls back to the longest known entity, so &amp renders as & but &notin becomes &not followed by "in" — that fallback underlies many "the entity shows wrong" problems.

Input&amp; &lt; &#65; &#x41;
Output& < A A (decimal and hex numeric entities are equivalent; &amp; shows as &)

Measured on This Page

Fixed: astral planeThe old decode used String.fromCharCode, which only covers the BMP (U+0000–FFFF), so &#128512; (😀, U+1F600) truncated to the private-use U+F600 — every emoji and astral character was broken. With fromCodePoint both &#128512; and &#x1F600; yield 😀
Invalid code points&#xD800; (surrogate) and out-of-range values are left verbatim instead of producing malformed strings — silently substituting a replacement glyph would be worse
Named entitiesThe five basics &amp; &lt; &gt; &quot; &#39; all correct
Encoding<a & b> → &lt;a &amp; b&gt;; quotes/apostrophes → &quot;/&#39; — only the necessary five characters, CJK is not entity-encoded
Empty inputClearing the input leaves the output empty with no leftovers

Two entity pitfalls, both handled: numeric references come in decimal AND hex (&#39; equals &#x27;) and need separate patterns; and code points beyond the BMP must use fromCodePoint — fromCharCode truncates U+1F600 to U+F600, a private-use character, which is the most common reason decoded emoji turn into boxes. Named coverage is limited to the five basics plus nbsp; &copy; or &mdash; pass through untouched — use a full HTML5 entity table (about 2200 entries) when you need them all.

How this was measured: Nine decode cases (named, decimal, hex, astral, surrogate) and two encode cases compared character by character, before and after the fix. · Measured 2026-10-31

How to Use

  1. Open "HTML Entities"
  2. Choose encode or decode, then paste into the left pane
  3. The right pane shows entities or decoded text as you type
  4. Use Swap to run the reverse conversion
  5. Copy the output with the icon in the result header

Use Cases

  • XSS escaping — Convert angle brackets and quotes in user input before injecting it into a page.
  • Show source code — Encode tags when displaying HTML in a blog so the browser shows them literally.
  • Email templates — Turn copyright and currency symbols into entities for consistent rendering across clients.
  • Decode scraped text — Restore readable characters from scraped content containing &amp; or &#39;.
  • Clean attribute values — Encode double quotes in title or alt text to avoid closing the attribute early.
  • JSON embedding — Encode HTML tags in a JSON string field to safely embed it inside a script tag.
  • Attribute injection — Convert special characters in dynamic class or data attributes to prevent markup breakage.

FAQ

Named vs numeric entities?

Named entities like &copy; are readable but depend on the HTML spec name table; numeric entities &#169; and &#xA9; reference Unicode code points directly, offering broader compatibility and safer use in XML.

Is encoding the five special chars enough?

In HTML body text you usually only need & < >, plus the matching quote inside attribute values. If the declared charset is uncertain, encoding all non-ASCII characters is safer.

Does escaping fully stop XSS?

Entity encoding prevents text from being parsed as tags, but JavaScript, URL, and CSS contexts each need their own escaping. HTML entities alone do not cover every injection surface.

Why does decoded &nbsp; look like a space but copies oddly?

&nbsp; is a non-breaking space (U+00A0), a different code point from a normal space (U+0020). They look alike but are treated differently in search and regex.

Can it process a whole HTML block?

Yes, just paste the text. If you instead want to strip HTML into plain text, use a dedicated HTML-to-text tool; this one focuses on character-level entity coding.

Why does &amp; in my page display as just &?

Because the browser decodes entities when parsing HTML, so &amp; is rendered as the literal & character — that is correct, expected behavior. Trouble arises when escaping goes wrong: if you double-encode an already-encoded string you get &amp;amp; and the page literally shows &amp;; if you leave a raw & un-encoded, some parsers mistake it for the start of a malformed entity and drop the rest of the sequence. Encode exactly once per output and keep the source text un-encoded in storage.

Entities vs escaping — are these the same thing?

Escaping is the act of replacing a reserved character with an entity so it is treated as literal text; an entity such as &lt; is the encoded form that results. The two terms usually describe the same encode/decode cycle. Context matters: frameworks like Vue/React auto-escape by default, and setting text via textContent is safe, whereas manually building innerHTML requires you to escape every dynamic value. Only encode once per output layer to avoid &amp;amp; double-encoding.

When are HTML entities actually required?

Three cases: showing reserved characters (< > &) as text, displaying symbols unavailable on a keyboard (©, →, non-breaking space), and preventing user input from being parsed as tags (the first layer of XSS defence). Plain text in either language needs no escaping.