DevAcademy
LearnHTMLHTML Entities
IntermediateHTML

HTML Entities

Learn how to safely display reserved characters and special symbols in HTML using character entities.

Reading Time

10 min

Lesson

Lesson 20 of 27

Why Entities Exist

Some characters, like < and >, have special meaning in HTML because they define tags. To display them as literal text rather than markup, you need to use an entity instead.

Common Entities

EntityRenders AsMeaning
&lt;<Less than
&gt;>Greater than
&amp;&Ampersand
&quot;"Double quote
&apos;'Apostrophe
&nbsp; Non-breaking space
&copy;©Copyright symbol
&hearts;Heart symbol

Using Entities

<p>Use &lt;div&gt; to group content.</p>
<p>Terms &amp; Conditions</p>
<p>&copy; 2026 DevAcademy</p>
Output

Numeric Character References

Any Unicode character can also be written using a numeric reference: &#160; for a non-breaking space, or &#x00A9; using its hexadecimal code point.

Numeric References

<p>&#169; 2026 DevAcademy</p>
<p>&#x2764; I love HTML</p>
Output

The Non-Breaking Space

&nbsp; inserts a space that browsers will not collapse or break a line at — useful for keeping two words together, like "10&nbsp;km".

Escape User-Generated Content

When displaying text that comes from users (comments, form input), always escape characters like < and & to entities on the server, or use a templating system that does so automatically. Failing to do this can lead to cross-site scripting (XSS) vulnerabilities.

Best Practice

Use named entities (&amp;, &lt;) for readability when writing markup by hand, and rely on your framework’s automatic escaping when rendering dynamic, user-supplied content.

Interview Questions

Quick Quiz

1. Which entity displays a literal less-than sign (<)?

2. Which entity represents a non-breaking space?

3. Why is escaping user-generated content important?