HTML Entities
HTML Entities
HTML entities are used to display reserved characters and special symbols that cannot be written directly in HTML.
Some characters, such as < and >, are reserved because they are used to define HTML tags.
Reserved Characters
If reserved characters are written directly in HTML text, the browser may interpret them as markup.
For example, the less-than and greater-than signs must be replaced with entities:
< = < > = >
Entity Names and Numbers
HTML entities can be written using either an entity name or an entity number.
Entity names are easier to read and remember:
< >
Entity numbers use numeric codes:
< >
Non-breaking Space
The non-breaking space entity prevents automatic line breaks between words.
This is useful for keeping related text together, such as units or abbreviations.
10 km/h 10 PM § 10
It can also be used to preserve multiple spaces, which are normally collapsed by the browser.
Common HTML Character Entities
| Character | Description | Entity Name | Entity Number |
|---|---|---|---|
| < | Less than | < | < |
| > | Greater than | > | > |
| & | Ampersand | & | & |
| " | Double quote | " | " |
| © | Copyright | © | © |
| € | Euro | € | € |
Note: Entity names are case sensitive.
Combining Diacritical Marks
Diacritical marks are symbols added to letters to change their pronunciation or meaning.
They can be combined with characters using entity numbers to produce accented letters:
à → à á → á â → â ã → ã
This method is useful when a specific character is not directly available in the page encoding.