Special Characters & Entities
A handful of characters have special meaning to HTML's parser itself — using them directly in regular text content causes the browser to misinterpret what's actually being said. Entities solve this: a special escape syntax that displays a character literally, without the browser trying to interpret it as markup.
Why This Is Necessary at All
< signals the start of a tag; & signals the start of an entity (covered in this chapter itself). Using either character literally in regular text content confuses the parser — entities exist specifically to write these characters safely.
The Essential Entities
| Entity | Displays as | Why it's needed |
|---|---|---|
| < | < | Opens every HTML tag — must be escaped to display literally |
| > | > | Closes every HTML tag — escaped for consistency, though less strictly required than < |
| & | & | Opens every entity, including itself — must be escaped to display a literal ampersand |
| " | " | Needed inside an attribute value itself wrapped in double quotes |
| ' | ' | Needed inside an attribute value wrapped in single quotes |
| | (non-breaking space) | A space that prevents a line break at that exact point — covered further below |
Named, Decimal, and Hexadecimal Entities
Every entity has a named form (easier for a human to read in source) and equivalent numeric forms — useful for characters that don't have a commonly memorised name.
Common Practical Entities
— The Non-Breaking Space
A regular space allows the browser to break a line at that point if needed for wrapping. behaves like a space visually but specifically prevents a line break there — keeping two words glued together on the same line.
What About Unicode Characters Like 日本語 or 水?
Modern HTML documents, declared with UTF-8 encoding (the now near-universal standard), can include almost any character — emoji, Japanese kanji, accented letters — directly in the source text, with no entity needed at all. Entities are specifically for the small set of characters that have special meaning to HTML's own parser (<, >, &, quote characters inside matching attribute quotes), not a general mechanism for "any character that isn't plain English."
Chapter 11 Quick Reference
- < / > / & — escape these whenever the literal <, >, or & character is genuinely intended in text
- " / ' — needed inside an attribute value matching the surrounding quote style
- Named vs numeric (© / ©) — equivalent forms; named is more readable in source
- — a space that prevents line-wrapping at that point; use sparingly, for meaningful pairs
- UTF-8 encoded documents can include non-English characters and emoji directly — entities are only for parser-significant characters
- Always escape user-submitted content before displaying it — the basis of XSS prevention
- Next chapter (final, Course 1): putting it all together — building a simple multi-page site structure