What are HTML entities and when are they needed?
HTML entities are escape codes like < that let you write characters which would otherwise be misread as HTML syntax (or aren't easy to type).
The problem they solve: a few characters have special meaning to the browser. If you literally type a <, the browser thinks a tag is starting. To display the character itself, you escape it with an entity — a code that begins with & and ends with ;. The ones that must be escaped because they collide with HTML syntax are:
| Character | Entity |
|---|---|
& |
& |
< |
< |
> |
> |
" |
" |
' |
' |
For example, to show the text 5 < 10 && 10 > 5:
<p>5 < 10 && 10 > 5</p>
Entities were also historically used for accented or non-keyboard letters — for instance ü could be written ü. That use is now considered outdated: the modern approach is simply to declare a Unicode character set in the head, after which you can type almost any character directly:
<meta charset="utf-8">
UTF-8 covers virtually every character on Earth, so entities are now needed only for the handful that clash with HTML's own syntax.
Go deeper:
Entity (character reference) — MDN Glossary — what an HTML entity is and how it maps to a character.
Character encodings in HTML — Wikipedia — named vs numeric character references and how UTF-8 made most entities unnecessary.