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
| Type | Pattern | Copyright 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 " for a literal double quotation mark. Inside a single-quoted attribute, use ' or ' for a literal apostrophe.
The greater-than sign is usually safe in text, but > 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: &, not &.