Understanding HTML Entities

HTML entities are used to display special characters that are not easily typed on a keyboard or might be interpreted incorrectly by the browser. Entities begin with an ampersand (&) and end with a semicolon (;).

Common HTML Entities

Here are some common HTML entities:

< - < (Less-than sign)
> - > (Greater-than sign)
& - & (Ampersand)
" - " (Double quotation mark)
' - ' (Single quotation mark)

These entities are used to include special characters in your HTML content. For example, if you want to display a less-than sign (<) in your text, you would use &lt; in your HTML code.

Using HTML Entities for Special Characters

HTML entities are also useful for special characters such as mathematical symbols, currency signs, and others:

&amp;copy; - &amp;copy; (Copyright symbol)
&amp;euro; - &amp;euro; (Euro symbol)
&amp;yen; - &amp;yen; (Yen symbol)
&amp;plusmn; - &amp;plusmn; (Plus-minus sign)

These entities make it easy to include a wide range of symbols and special characters in your web pages.

HTML Entities in Practice

Here’s an example of how you might use HTML entities in a real-world scenario:

&lt;p&gt;The price is &amp;euro;20.00, and the tax is &amp;plusmn;5%&lt;/p&gt;

This code will display: "The price is €20.00, and the tax is ±5%".

Practice Exercise

Try creating a web page that uses various HTML entities to display special characters, such as currency symbols, mathematical operators, and other symbols. Make sure to include both commonly used entities and less familiar ones.

Proceed to Lesson 8