19. HTML Entities

What you will learn

  • What an HTML entity is
  • Why some characters must be written as entities
  • The most useful entities
  • How to show HTML code on a page

Why entities exist

Some characters have a special meaning in HTML. The less-than sign < starts a tag. If you type it in your text, the browser may think a tag is beginning. To show these characters safely, you write an entity instead.

Entity syntax

An entity begins with an ampersand (&) and ends with a semicolon (;). You can use a name or a number:

Syntax

&entity_name;
&#entity_number;

Common entities

Result Name Number
< (less than) &lt; &#60;
> (greater than) &gt; &#62;
& (ampersand) &amp; &#38;
" (double quote) &quot; &#34;
© (copyright) &copy; &#169;
€ (euro) &euro; &#8364;
(non-breaking space) &nbsp; &#160;

Showing code on a page

To display a tag as text, replace < with &lt; and > with &gt;. Every code example in this tutorial is written this way.

Example

<p>Use the &lt;p&gt; element for paragraphs.</p>
<p>5 &lt; 10 and 10 &gt; 5</p>
<p>&copy; 2026 BeingXpert</p>

Output

Use the <p> element for paragraphs.

5 < 10 and 10 > 5

© 2026 BeingXpert

The non-breaking space

Browsers collapse several spaces into one. A non-breaking space (&nbsp;) stays put, and it also stops a line from breaking between two words. This is useful for keeping a number and its unit together, such as 10&nbsp;km.

Do not use many &nbsp; entities to create layout space. Use CSS margins and padding instead.

Do you always need entities?

If your file is saved as UTF-8 and has <meta charset="UTF-8">, you can type characters such as © or € directly. You still need entities for <, >, and &, because they have special meaning in HTML.

Common mistakes

  • Forgetting the semicolon at the end, such as &copy.
  • Typing a bare < in text and finding that part of the page disappears.
  • Misspelling the entity name. The browser then shows the raw text.
  • Using &nbsp; repeatedly to indent text.

Exercise

Write a paragraph that shows the text Use <br> for a line break on the page, including the visible angle brackets.

Show solution
<p>Use &lt;br&gt; for a line break</p>

Knowledge check

1. How does every entity begin and end?

It begins with & and ends with ;.

2. Which entity displays the < sign?

&lt;

3. Which entity creates a space that will not collapse?

&nbsp;

Summary

  • Entities let you show reserved and special characters.
  • They use the form &name; or &#number;.
  • Use &lt;, &gt;, and &amp; to display code.
Scroll to Top