HTML Character References Explained

An HTML character reference tells the browser to insert a character without placing that character literally in the source. References begin with an ampersand and end with a semicolon. They are especially useful for HTML syntax characters, invisible spacing characters, and symbols that are difficult to type.

Named, Decimal, and Hexadecimal Forms

TypePatternCopyright example
Named&name;©
Decimal numeric&#number;©
Hexadecimal numeric&#xhex;©

Named references exist only for a defined collection of characters. Numeric references can represent any valid Unicode scalar value.

When References Are Required

Inside normal text, escape & when it could start a character reference and escape < when it could be interpreted as markup. Inside a double-quoted attribute, use &quot; for a literal double quotation mark. Inside a single-quoted attribute, use &apos; or &#39; for a literal apostrophe.

The greater-than sign is usually safe in text, but &gt; can improve symmetry and clarity when displaying code examples.

Always Include the Semicolon

HTML accepts a limited set of legacy named references without a semicolon in some contexts, but relying on that behavior can create ambiguous parsing. Write the final semicolon every time: &amp;, not &amp.