By Docify

Named vs Numeric HTML Entities: Names vs Code Points

• 6 min read

Encoding Price: 5 < 10 & 10 > 5, "sale" isn't on. writes Price: 5 &lt; 10 &amp; 10 &gt; 5, &quot;sale&quot; isn&#39;t on.. A named character reference is a mnemonic (&lt;). A numeric one is the Unicode code point: decimal &#60; or hex &#x3C;. Encode writes & first so later passes cannot double-escape an entity. Apostrophe is &#39; because HTML 4.01 never defined &apos;. Decode expands those five lowercase names plus numeric refs — &#x3C; becomes <, but &#X3C; stays written. The live regex also requires a trailing semicolon, so &lt stays written and &lt; becomes <. Encode does not call String.prototype.normalize. Decode output of &#xE9; writes NFC é (U+00E9). Decode output of e&#x301; writes NFD e + U+0301. &eacute; stays written. Compose e + U+0301 to é (U+00E9) on /unicode-normalize/. Not &nbsp; and not the full HTML5 table. Nothing is uploaded.

Markup needs a way to write the characters that would otherwise start a tag or an entity. The live HTML encoder escapes five of them and decodes a small, named subset plus numeric references. This page names the three reference forms, the HTML 4.01 &apos; gap, and what a browser innerHTML parser would do that this tool does not.

How HTML entity encoding works

Encode writes the five markup characters as named or numeric references. Apostrophe is &#39;, not &apos;.

Price: 5 < 10 & 10 > 5, "sale" isn't on.
Price: 5 &lt; 10 &amp; 10 &gt; 5, &quot;sale&quot; isn&#39;t on.

HTML encoding does not normalize Unicode

Encode does not call String.prototype.normalize. Non-ASCII letters stay as themselves, so encoding NFC é returns é and encoding NFD e + U+0301 returns e + U+0301. Decode output of &#xE9; (or &#233;) writes NFC é. Decode output of e&#x301; (or e&#769;) writes NFD e + U+0301. &eacute; stays written. Composition under UAX #15 (e + U+0301 → é, U+00E9) is a separate step on /unicode-normalize/. The encoder leaves combining marks as typed.

&#xE9; → é (U+00E9) · e&#x301; → e + U+0301 · &eacute; stays &eacute;

Three ways to write the same character

Named: mnemonic, case-sensitive

HTML calls these named character references (HTML 4.01 said “character entity references”). The form is &name;. The five markup-significant names the live decoder accepts are amp (U+0026), lt (U+003C), gt (U+003E), quot (U+0022), and apos (U+0027). Names are case-sensitive. HTML5 also defines &LT; for the same less-than; Docify does not expand that uppercase form.

&lt; → U+003C · &LT; stays &LT;

Decimal: &#D;

HTML 4.01 §5.3.1: “&#D;” is the ISO 10646 (Unicode) decimal code point. Less-than is 60, ampersand is 38, apostrophe is 39. The live decoder parses the digits with Number.parseInt(..., 10) and then String.fromCodePoint. Zero, negative values, and anything above U+10FFFF stay as written.

&#60; → U+003C

Hex: &#xH; (XML wants lowercase x)

The same code point in hex: less-than is 3C. HTML 4.01 allows &#xH; or &#XH;. XML 1.0 requires a lowercase x. The live decoder regex is x[0-9a-fA-F]+, so &#x3C; and &#x3c; become <, but &#X3C; stays written. Hex digits themselves are case-insensitive (3C and 3c). Encode never writes numeric refs for &, <, >, or " — only the apostrophe is numeric.

&#x3C; → U+003C · &#X3C; stays &#X3C;

Ampersand first, apostrophe numeric

Why & is replaced first

Every character reference begins with &. If you first turn < into &lt; and then escape every remaining ampersand, that entity becomes &amp;lt;. Decoding once yields the six characters &lt;, not a less-than. Encode therefore replaces & with &amp; before <, >, ", and the apostrophe. Non-ASCII letters stay as themselves — this is not UTF-8 percent-encoding. Encoding NFC é returns é; encoding NFD e + U+0301 returns e + U+0301. Decode output of &#xE9; writes NFC é. Decode output of e&#x301; writes NFD e + U+0301. NFC normalization e + U+0301 → é (U+00E9) is /unicode-normalize/.

Encoding Price: 5 < 10 & 10 > 5, "sale" isn't on. writes Price: 5 &lt; 10 &amp; 10 &gt; 5, &quot;sale&quot; isn&#39;t on.

HTML 4.01 has no &apos;

W3C HTML 4.01 §24 ships three entity sets: Latin-1 (including &nbsp; U+00A0 and &copy; U+00A9), symbols and Greek, and markup-significant names. Those markup names include &amp;, &lt;, &gt;, and &quot;. There is no &apos;. XML 1.0 predefined five entities and added it. WHATWG HTML’s named-character table later maps apos; to U+0027. A document served as HTML 4.01 may show the six characters &apos; literally. Decimal &#39; and hex &#x27; are the same apostrophe in HTML 4.01, XML, and HTML5, so Encode always writes &#39;. Decode still accepts &apos;.

What Decode does not parse

Not the HTML 4.01 or WHATWG named tables

HTML 4.01’s Latin-1 list includes &nbsp;. WHATWG HTML lists more than two thousand named references (including many without a trailing semicolon, for legacy pages). Docify decode is a regex on those five names plus &# decimal or &#x hex, and that regex requires a trailing semicolon. A WHATWG HTML parser may expand the semicolon-less name lt; this page does not. Then String.fromCodePoint for scalars 1–0x10FFFF. Surrogates U+D800–U+DFFF stay written. So &nbsp; and &copy; remain those strings unless you wrote the numeric form &#160; or &#xA0;.

&lt stays &lt · &lt; → < · &#60 stays &#60 · &#60; → < · &nbsp; stays &nbsp; · &#160; → U+00A0

Not innerHTML, not a sanitizer

Assigning a string to innerHTML parses markup: tags run, the full HTML named-entity table applies, and a <script> or event-handler attribute is a different job. This page does not do that. It is also not encodeURI or encodeURIComponent (spaces stay spaces; they do not become %20). Escaping five characters is not XSS protection and not a HTML sanitizer. Encode and Decode are buttons, not as-you-type.

Escape or decode the five markup characters

Ampersand first. Apostrophe is &#39;. Nothing is uploaded.

Use HTML Encoder →

FAQ

What is the difference between named and numeric HTML entities?
Named entities use readable names like &amp;amp; for &amp;. Numeric entities use code points like &amp;#38; or &amp;#x26;.
Which entities are widely supported?
Basic entities (&lt; &gt; &amp; &quot;) work everywhere. Some named entities are HTML5 only.
When should I use entities?
Use entities for < > & characters that have special meaning in HTML. Most other characters can be UTF-8.
Does this tool upload my data?
No. All encoding runs in your browser using JavaScript. Nothing is sent to a server.

Related