Dremendo Tag Line

Entity Codes in HTML

Character Codes

In this lesson, we will learn about entity codes and how to use them in an HTML document.

What are Entity Codes in HTML

In HTML, entity codes are special sequences of characters that are used to represent reserved characters, symbols, and special characters that have special meanings in HTML. They are used to display these characters correctly on web pages, regardless of the encoding or character set being used.

Entity codes start with an ampersand (&) and end with a semicolon (;). The code represents a specific character or symbol, and when used in HTML, the corresponding character or symbol is displayed.

For example, the entity code &lt; represents the less-than symbol (<), and &gt; represents the greater-than symbol (>). These codes are used to display angle brackets without being interpreted as HTML tags.

video-poster

List of Essential Entity Codes

There are lots of entity codes available in HTML. The table below contains the most commonly used essential entity codes used frequently in an HTML document.

Character Entity Name Entity Code Description
< &lt; &#60; Less than
> &gt; &#62; Greater than
& &amp; &#38; Ampersand
! &excl; &#33; Exclamation mark
" &quot; &#34; Double quotation mark
' &apos; &#39; Single quotation mark
© &copy; &#169; Copyright symbol
® &reg; &#174; Registered trademark symbol
&trade; &#8482; Trademark symbol
&euro; &#8364; Euro symbol
£ &pound; &#163; Pound symbol
$ &dollar; &#36; Dollar symbol
¢ &cent; &#162; Cent symbol
&#8377; Indian Rupee symbol
¥ &yen; &#165; Yen symbol
§ &sect; &#167; Section symbol
° &deg; &#176; Degree symbol
&#8451; Celsius symbol
&#8457; Fahrenheit symbol
± &plusmn; &#177; Plus-minus symbol
× &times; &#215; Multiplication symbol
÷ &divide; &#247; Division symbol
&ne; &#8800; Not equal to symbol
½ &frac12; &#189; Fraction one half symbol
&frac13; &#8531; Fraction one third symbol
¼ &frac14; &#188; Fraction one quarter symbol
&frac23; &#8532; Fraction two third symbol
α &alpha; &#945; Alpha symbol
β &beta; &#946; Beta symbol
γ &gamma; &#947; Gamma symbol
δ &delta; &#948; Delta symbol
ω &omega; &#969; Omega symbol
π &pi; &#960; Pi symbol
Σ &sum; &#931; Sigma symbol
&radic; &#8730; Square root symbol
&infin; &#8734; Infinity symbol
&larr; &#8592; Left arrow symbol
&rarr; &#8594; Right arrow symbol
&uarr; &#8593; Up arrow symbol
&darr; &#8595; Down arrow symbol

Note: Some entity codes do not have any entity names. For example, the indian rupee symbol does have an entity name.

The &nbsp Entity Code

In HTML, the &nbsp; entity code represents a non-breaking space. It is used to insert a space between elements or text that prevents the browser from converting multiple spaces into a single space.

In HTML multiple consecutive spaces are displayed as a single space. However, when you use &nbsp;, it creates a space that is not collapsed, and each &nbsp; entity will be displayed as a separate space.

This is useful in situations where you want to ensure that certain elements or text remain visually separated by a specific amount of spaces.

Here is an example of how to use the &nbsp; entity in an HTML document.

Example

<!doctype html>
<html>

<head>
	<meta charset="utf-8">
	<title>&nbsp Example</title>
</head>

<body>
	<!-- without using nbsp -->
    <p>This is some     text with multiple        spaces.</p>

    <!-- using nbsp -->
    <p>This is some&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text with multiple&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;spaces.</p>
</body>

</html>

In the above example, the first paragraph has multiple normal spaces, whereas in the second paragraph, multiple &nbsp; entities are inserted between the words to create specific spacing. When rendered by the browser, the multiple spaces in the first paragraph will be converted into a single space, but in the second paragraph, the multiple &nbsp; will be displayed as separate non-breaking spaces.