HTML entities
HTML entities are special codes used in HTML to represent characters that either have a reserved meaning in HTML or are not easily typed or displayed in the content. These entities allow you to include special symbols, characters, and reserved HTML characters in your web pages without causing issues with the markup or display.
Why HTML Entities Are Used:
Reserved Characters: Some characters have special meanings in HTML. For example, the
<
and>
characters are used to define HTML tags, so if you want to display them as text, you need to use HTML entities.Special Symbols: Some symbols (like
©
,®
, or€
) aren't easily typed from a standard keyboard, so HTML entities are used to display them.Non-ASCII Characters: Entities are also used to represent characters from different languages or character sets that aren't part of the standard ASCII set.
Syntax of HTML Entities:
An HTML entity begins with &
and ends with ;
. Inside these delimiters, there is either:
A named entity (e.g.,
&
).A numeric entity in decimal form (e.g.,
©
).A numeric entity in hexadecimal form (e.g.,
©
).
Common HTML Entities:
Character | Entity Name | Entity Number (Decimal) | Entity Number (Hex) | Description |
< | < | < | < | Less than sign (used in HTML tags) |
> | > | > | > | Greater than sign (used in HTML tags) |
& | & | & | & | Ampersand |
" | " | " | " | Double quote |
' | ' | ' | ' | Single quote or apostrophe |
© | © | © | © | Copyright symbol |
® | ® | ® | ® | Registered trademark symbol |
™ | ™ | ™ | ™ | Trademark symbol |
£ | £ | £ | £ | Pound sign |
€ | € | € | € | Euro sign |
¢ | ¢ | ¢ | ¢ | Cent sign |
|   |   | Non-breaking space |
Examples of HTML Entities:
Displaying reserved characters in HTML:
<p>To use a less than symbol, type: < instead of <</p>
Displaying special symbols:
<p>Copyright symbol: © 2024 MyWebsite</p>
Using non-breaking space (
):<p>Normal space vs non-breaking spaces.</p>
This will display extra spaces because
prevents the collapsing of multiple spaces, unlike regular spaces in HTML.
Subscribe to my newsletter
Read articles from dheeraj koranga directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by