Entities in HTML, also known as HTML character entities or HTML entities, are special codes that represent characters in HTML that are reserved or cannot be easily typed on a standard keyboard. They are used to ensure that certain characters are displayed correctly in the browser.
Syntax of HTML Entities
HTML entities start with an ampersand (&
) and end with a semicolon (;
). The entity name or number is placed between these two symbols.
There are two types of HTML entities:
- Named entities: These use a descriptive name.
- Numeric entities: These use a numeric code.
Common Named Entities
Reserved Characters
&
- & (ampersand)<
- < (less than)>
- > (greater than)"
- " (double quote)'
- ' (single quote, apostrophe)
Special Characters
- Non-breaking space©
- © (copyright)®
- ® (registered trademark)™
- ™ (trademark)€
- € (euro)¢
- ¢ (cent)£
- £ (pound)¥
- ¥ (yen)§
- § (section sign)¶
- ¶ (paragraph sign)•
- • (bullet)…
- … (ellipsis)
Numeric Entities
Numeric entities can be written in decimal or hexadecimal form.
Decimal
"
- " (double quote)&
- & (ampersand)<
- < (less than)>
- > (greater than)
Hexadecimal
"
- " (double quote)&
- & (ampersand)<
- < (less than)>
- > (greater than)
Example Usage
<!DOCTYPE html> <html> <head> <title>HTML Entities Example</title> </head> <body> <p>Use & to represent an ampersand (&).</p> <p>Less than < and greater than > signs.</p> <p>Quotes: "Double" and 'Single'.</p> <p>Non-breaking space: keeps text together.</p> <p>© 2024 Company Name. All rights reserved.</p> <p>Price: 100$, 80€, 70£, 1000¥.</p> </body> </html>
In this example:
&
is used to display an ampersand.<
and>
are used for the less than and greater than symbols."
and'
are used for double and single quotes.
is used for a non-breaking space.©
,$
,€
,£
, and¥
are used for copyright, dollar, euro, pound, and yen symbols, respectively.