HTML Entities Explained: The Named, Decimal, and Hex Forms

💡 ~12K searches/mo💰 CPC: $0.8-2⏱️ 7 min read

An HTML entity is the markup-safe spelling of a character: an ampersand, a name or number, a semicolon. &amp; renders as &, &lt; as <, &copy; as ©, and the numeric &#169; or &#xA9; reaches the same copyright sign through its Unicode code point. That's the whole mechanic. What trips people up is the surrounding rules: which characters actually need escaping, why there are three syntaxes, and the traps (nbsp, case sensitivity, double decoding). This guide covers all of it, with a table you can paste from.

Advertisement

The three syntaxes, one character

Every entity names a Unicode code point, and every Unicode character can be written three ways in HTML:

FormSyntaxExampleRenders
Named&name;&eacute;é (code point 233)
Decimal&#NNN;&#233;é
Hex&#xHH; (x or X)&#xE9;é

The three are interchangeable in output but not in tooling. Named entities are the readable choice for hand-written HTML. Decimal and hex work everywhere, including environments that only understand a few names — XML, for instance, defines exactly five named entities (&amp; &lt; &gt; &quot; &apos;) and requires numeric references for everything else.

What actually needs escaping

Less than most escaped documents contain. The rules for text content:

Everything else — accented letters, currency symbols, emoji — needs no entity at all in a UTF-8 document. Entities for those exist for three honest reasons: keyboards that can't type them, systems that mangle encodings, and source code where the raw character would be invisible or confusable (two of them, &nbsp; and soft hyphen, are genuinely invisible).

The nbsp trap and other invisible characters

&nbsp; is U+00A0, a non-breaking space. Two things make it special: browsers won't collapse runs of it (normal spaces collapse to one) and won't break lines at it. Paste one from a rendered web page into a code editor or terminal and you get a "space" that breaks parsing, diffing, and column alignment, because it isn't a space. The same goes for &shy; (soft hyphen, U+00AD) and &zwnj;/&zwj;. When a string with "invisible" bugs shows up, decoding entities and grepping for U+00A0 is the standard first move — the HTML entity converter makes that a two-click job.

Case sensitivity and the Greek letters

Names are case-sensitive, and the case usually carries meaning. &pi; is lowercase π (945) while &Pi; is uppercase Π (928). &copy; and &COPY; both map to the copyright sign in HTML5's table, but &Copy; is nothing. Since the safe mental model is "names are case-sensitive, full stop," generators avoid the whole question by emitting numeric forms.

Convert entities both directions

Text in, entities out — named, decimal, or hex — and entities back to characters, all in your browser.

Open the HTML Entity Converter →

Single-pass decoding, or why &amp;lt; stays put

The string &amp;lt; is what you get when someone escapes the literal text &lt;. Decoding it once yields &lt; — correct. A decoder that loops until nothing changes would yield <, silently corrupting double-escaped content, which is exactly how stored-XSS bugs sneak through naive template systems. The HTML5 spec's own parsing decodes entities in one pass per text node. Any tool you use should do the same, and should leave unknown names (&fakeentity;) untouched rather than guessing.

Which names exist: the numbers behind the table

HTML5 defines 2,231 named character references — 2,125 with semicolons, plus legacy semicolon-less forms like &copy that survive from HTML 3.2 for browser-compatibility reasons nobody should rely on today. About 121 names cover daily writing: the markup specials, currency, typographic punctuation, math symbols, Greek letters, and the accented Latin-1 set. That's the working set in our converter's map; anything outside it falls back to numeric automatically.

For anything serious — parsing untrusted HTML, handling XML, mapping all 2,231 names — the JavaScript ecosystem standardizes on fb55/entities, a BSD-2-Clause licensed package that underlies the htmlparser2 family and ships encode/decode maps for both HTML and XML modes. It's the right dependency when a regex stops being enough; the license is permissive enough for commercial embedding with attribution preserved.

Entities vs URL encoding vs Base64

Three escaping systems that show up in the same bug reports but solve different problems:

Picking the wrong layer is a classic integration bug: percent-encoding HTML doesn't stop it from being parsed as markup, and entity-encoding a URL breaks the URL. Match the escape to the parser that will read the string.

Advertisement

Frequently Asked Questions

What characters must be escaped in HTML?

In text content: &, <, and (practically) >. The ampersand only strictly needs escaping when what follows could parse as an entity, and < only when followed by a letter, /, ! or ?, but escaping all three unconditionally is the safe habit. In attribute values, also escape the quote character delimiting the attribute. Everything else is optional; entities for accented letters and symbols are a compatibility convenience, not a requirement in UTF-8 documents.

Should I use named entities or numeric character references?

Named for the specials (&amp; &lt; &gt;) because they read clearly in source. Numeric for everything else if the output feeds a system that only understands a subset of names — email clients, older CMS templating, some XML processors. XML defines exactly five named entities, so numeric is the only portable choice there. If your document is UTF-8 and stays UTF-8, raw characters are usually fine and smaller.

Why does &nbsp; show up as a visible box or weird character in my email?

Encoding mismatch. The document claims one character encoding (say ISO-8859-1) while the bytes are in another (UTF-8), or vice versa, so U+00A0 or the entity's target renders through the wrong table. Declare <meta charset="UTF-8"> as the first thing in head, send the matching Content-Type header, and the problem disappears.

Do I still need entities in a UTF-8 page?

Only for markup-significant characters. Modern HTML is UTF-8 by default, so é, ©, and even emoji can be written as raw characters. Entities remain mandatory for & < > in text, useful in generated HTML where you can't be sure of the encoding, and handy in email HTML where client support is years behind browsers.

What library do developers use for entity handling in JavaScript?

The de facto standard is fb55/entities (BSD-2-Clause licensed), which powers the htmlparser2 ecosystem and supplies decode/encode maps for HTML and XML. For a handful of characters, a regex over named and numeric patterns is fine — this site's converter does exactly that in about 40 lines — but for untrusted input a maintained library handles the 2,231 HTML5 names, entity edge cases, and XML's stricter rules for you.

Related Tools