Web DevelopmentAlso known as: HTML Entities, Character Entities
HTML Entities
A piece of text that begins with an ampersand and ends with a semicolon, used to display reserved characters or invisible characters in HTML.
An HTML Entity is a snippet of text that begins with an ampersand (&) and ends with a semicolon (;). Entities are frequently used to display reserved characters (which would otherwise be interpreted as HTML code) or invisible characters (like non-breaking spaces).
Why use HTML Entities?
There are several reasons to use HTML entities in your web pages:
- Reserved Characters: Some characters are reserved in HTML. For example, you cannot use the less-than (
<) or greater-than (>) signs directly in your text because the browser will mix them up with HTML tags. To display<p>, you must write<p>. - Invisible Characters: The most common invisible character entity is the non-breaking space (
). Browsers normally truncate multiple spaces in HTML code into a single space, but you can force multiple spaces by using non-breaking space entities. - Special Symbols: Many mathematical, technical, and currency symbols (like ©, ™, €, £) are not present on a standard keyboard and can be inserted using entities.
Format
HTML entities can be written in three ways:
- Entity Name: Easier to remember, but not all browsers support all entity names. Example:
©for the copyright symbol. - Decimal Number: Supported universally. Uses the format
&#[number];. Example:©for the copyright symbol. - Hexadecimal Number: Uses the format
&#x[hex_number];. Example:©for the copyright symbol.
Common HTML Entities
| Character | Description | Entity Name | Decimal |
|---|---|---|---|
< |
Less than | < |
< |
> |
Greater than | > |
> |
& |
Ampersand | & |
& |
" |
Double quote | " |
" |
' |
Single quote | ' |
' |
| Non-breaking space | |
  |