When you create a webpage, you often need to display characters that are not available on a standard keyboard. These could be special characters like the copyright symbol, accented letters in foreign languages, or mathematical symbols. To solve this problem, HTML uses a system of codes called entities, which allows you to display these characters on your page.
In this blog, we'll explore what HTML entities are, how to use them, and provide some examples.
HTML entities are codes that represent special characters in HTML. They are used to display characters that are not available on a standard keyboard or to prevent HTML from interpreting certain characters as code. For example, the less than sign "<" is interpreted as the beginning of an HTML tag, so if you want to display it on your page, you need to use an HTML entity like "<".
HTML entities are written as an ampersand (&) followed by a name or a number, and then a semicolon (;). There are two types of entities: named entities and numeric entities.
Named entities are codes that represent characters by their names. They are easier to remember and use than numeric entities. For example, the copyright symbol can be displayed using the named entity "©". Here are some common named entities:
- non-breaking space
© - copyright symbol
® - registered trademark symbol
™ - trademark symbol
< - less than sign
> - greater than sign
& - ampersand
Numeric entities are codes that represent characters by their Unicode code point number. They are useful when you need to display characters that don't have a named entity. For example, the accented letter "é" can be displayed using the numeric entity "é". Here are some examples of numeric entities:
© - copyright symbol
® - registered trademark symbol
™ - trademark symbol
< - less than sign
> - greater than sign
& - ampersand
To use an HTML entity, simply replace the character with the corresponding code. For example, if you want to display the copyright symbol on your page, you would use the named entity "©". Here's an example:
This will display the copyright symbol followed by the text "© 2023 My Company. All rights reserved.".
If you need to use a character that doesn't have a named entity, you can use a numeric entity. For example, if you want to display the accented letter "é" on your page, you would use the numeric entity "é". Here's an example:
This will display the text "La Cité de l'Amour (The City of Love)".
HTML entities are an essential tool for displaying special characters on your web pages. By using named or numeric entities, you can display characters that are not available on a standard keyboard or prevent HTML from interpreting certain characters as code. With this knowledge, you can add a new dimension to your web pages and make them more professional and attractive.