Some characters have special meaning in HTML — like < and > which start and end tags. If you want to display these characters as text, you must use HTML entities.
An HTML entity is a code that the browser converts to the actual character. It always starts with & and ends with ;.
<p>5 < 10</p> <!-- displays: 5 < 10 -->
<p>10 > 5</p> <!-- displays: 10 > 5 -->
| Entity | Character | Description |
|---|---|---|
< | < | Less-than sign |
> | > | Greater-than sign |
& | & | Ampersand |
" | " | Double quote |
' | ' | Apostrophe / single quote |
| (space) | Non-breaking space |
© | © | Copyright symbol |
® | ® | Registered trademark |
™ | ™ | Trademark symbol |
€ | € | Euro sign |
£ | £ | Pound sign |
— | — | Em dash |
– | – | En dash |
… | … | Ellipsis |
Every entity can also be written as a numeric code using the Unicode code point:
< is the same as < or <
© is the same as © or ©
Use whichever form is clearest. Named entities like © are usually more readable.
)A regular space allows the browser to break a line there. prevents the line break:
<!-- No line break between "100" and "km/h" -->
<p>The car travels at 100 km/h.</p>
Also useful for adding extra spacing (though CSS is usually better for this).
If you're writing HTML tutorials and want to show <h1> literally on the page:
<p>The heading tag looks like this: <h1>Title</h1></p>
Displays as: The heading tag looks like this: <h1>Title</h1>
5 < 10 and 10 > 5 using entities.© 2024 Your Name. All rights reserved.& to display a literal & (e.g., HTML & CSS). to prevent a line break between two words.Use < for < and > for > when you want to display them as text (not as tags).