Why HTML entities exist
HTML gives special meaning to a handful of characters. A < starts a tag, an & starts an entity reference, and a quote closes an attribute value. To display those characters as text rather than have the browser act on them, they have to be written as references β <, &, ".
Getting this wrong is how cross-site scripting happens. If user-supplied text containing <script> is written into a page unescaped, the browser runs it. Escaping turns it into inert text that displays as typed.
The three reference formats
- Named β
©, . Readable, but only a fixed list of names exists. - Decimal β
©. Works for any Unicode code point. - Hexadecimal β
©. Same, written in hex, which matches how code points are usually documented.
Extended mode escapes every non-ASCII character as a numeric reference. That is occasionally required by systems that cannot carry UTF-8, but for a modern page serving charset=utf-8 it is unnecessary and makes the source harder to read.
For escaping text destined for a URL rather than HTML, use the URL encoder. To tidy the markup itself, use the HTML beautifier.