HTML · Chapter 32 of 45

HTML Entities

HTML entities represent reserved or special characters that would otherwise be interpreted as code, like < and >, or characters not easily typed, like © or é.

Entities start with an ampersand (&) and end with a semicolon (;), and come in named form (&copy;) or numeric form (&#169;).

Syntax
&entityname; or &#code;

Why entities are needed

Characters like < and > have special meaning in HTML syntax. Writing them literally could be misinterpreted as the start of a tag, so entities like &lt; and &gt; are used instead.

Named vs numeric entities

Named entities are easier to read (&amp; for &). Numeric entities (&#38;) work for any Unicode character, even ones without a common name.

Example 1 (html)
<p>5 &lt; 10 and 10 &gt; 5</p>
Output
5 < 10 and 10 > 5

&lt; and &gt; display literal less-than and greater-than symbols.

Example 2 (html)
<p>&copy; 2024 MyCompany. Caf&eacute; is open.</p>
Output
© 2024 MyCompany. Café is open.

&copy; and &eacute; render special typographic characters.

Key points

  • Entities start with & and end with ;.
  • &lt; and &gt; escape < and > characters.
  • &amp; escapes the ampersand itself.
  • Numeric entities (&#code;) work for any Unicode character.
💡 Note: Forgetting to escape < or > inside text content is a common source of broken page rendering.

📝 Quick Quiz

1. What does &lt; display?

2. How do HTML entities start and end?

3. Which entity represents the ampersand character itself?