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) | < |
< |
| > (greater than) | > |
> |
| & (ampersand) | & |
& |
| " (double quote) | " |
" |
| © (copyright) | © |
© |
| € (euro) | € |
€ |
| (non-breaking space) | |
  |
Showing code on a page
To display a tag as text, replace < with < and > with >. Every code example in this tutorial is written this way.
Example
<p>Use the <p> element for paragraphs.</p>
<p>5 < 10 and 10 > 5</p>
<p>© 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 ( ) 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 km.
Do not use many 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
©. - 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
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 <br> 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?
<
3. Which entity creates a space that will not collapse?
Summary
- Entities let you show reserved and special characters.
- They use the form
&name;or&#number;. - Use
<,>, and&to display code.