HTML entities: the five characters and the rules behind them
Escape & < > " ' correctly, read decimal and hex references, and see why double-encoded &amp; breaks email templates and APIs.
2026-12-03
The five characters that break markup
In HTML, & starts a character reference and < starts a tag. A literal <div class="x"> in body text is parsed as an element, not shown, so displaying it means writing <div class="x">. The map is < to <, > to >, the double quote to ", the ampersand to &, and the apostrophe to ' or '.
Those five are the minimum. HTML5 defines over 2,000 named entities, from © and — to € and →. Most of the rest are typographic conveniences rather than structural requirements, which is why a narrow mode that touches only the five markup characters is enough for showing code.
Named versus numeric references
© and © both produce the copyright sign. The first is decimal 169, the second hexadecimal A9, and they point at the same code point, so the output is identical. The named form © is the same character once more; the three spellings differ only in how they are written.
Named entities are easier to read and to search for. Numeric references cover every code point, including characters that never received a name. HTML5's name list is long but not universal, and XML guarantees only five predefined names plus numeric references. Generated output is safer with numbers; files edited by hand are friendlier with names.
The semicolon is not optional
A reference ends at the semicolon. Browsers tolerate some missing semicolons in legacy parsing, which is exactly the trap: ¬it; becomes ¬it because ¬ is a valid entity. XML and XHTML require the semicolon strictly, so a document containing & without it can fail to parse rather than render.
HTML Entity Converter only recognises references that end with ;. Input such as & without the semicolon is left untouched instead of being half-converted. In decode mode the tool also counts the references it could not resolve, because its built-in table lists common names while any numeric reference with a valid code point is always decoded.
Double encoding: when & becomes &amp;
Encoding a string that is already encoded escapes the ampersand itself. & turns into &amp;, and a quote that was " becomes &quot;. Mail templates and JSON APIs are the usual suspects: one layer escapes on output, then another escapes again without checking what it received.
The symptom is text that renders as &quot; on the page. Decode once, read the remaining count, and run a second pass if one layer is left. To confirm what actually changed between the original and the repaired version, put both into Text Diff rather than comparing them by eye.
Encoding is not sanitising
Entity encoding controls how a character is written; it says nothing about whether the data is trustworthy. Escaping output is one layer of defence against cross-site scripting, but the authoritative checks belong on the server: validate types, lengths and allowed values, then escape according to context for HTML, attributes, JavaScript and CSS.
A content security policy and parameterised queries are still required. A database query assembled by string concatenation does not become safe because quotes were turned into ". Treat the converter as a formatting step; the decision about safety is made in code, not in a text box.
Emoji, URLs and pure ASCII
Emoji rarely have named entities and are written as numeric references. Anything at U+10000 or above needs the full code point, so 😀 is 😀 in decimal or 😀 in hex, and the surrogate range U+D800–U+DFFF is invalid on its own. URL encoding is a separate system: a space is in HTML but %20 in a URL, and the & separating query parameters must be %26, not &. Use URL Encoder/Decoder for that side.
Pure ASCII output still matters in three places: old mail systems that mangle 8-bit characters, database columns fixed to a single-byte encoding, and some translation files such as .po and .properties. Switching to decimal or hex makes every non-ASCII character survive ASCII-only transport, while the file stays readable and can be converted back at build time.