HTML Entities

Some characters have a special meaning in HTML and cannot be typed directly into the content. For example, the less-than sign (<) is used to open HTML tags, so typing it directly in text would confuse the browser into thinking a new tag is starting.

To display such characters safely, HTML entities (also called character references) are used. An entity is a code that represents a specific character.

HTML Entity Syntax

There are two ways to write HTML entities:

  • Named entity: &name; — Uses a descriptive name (e.g., &lt; for <)
  • Numeric entity: &#number; — Uses a decimal code (e.g., &#60; for <)
<p>A less-than sign: &lt;</p>
<p>A greater-than sign: &gt;</p>
<p>An ampersand: &amp;</p>
<p>A copyright symbol: &copy;</p>

Most Common HTML Entities

CharacterDescriptionNamed EntityNumeric Entity
<Less-than sign&lt;&#60;
>Greater-than sign&gt;&#62;
&Ampersand&amp;&#38;
"Double quotation mark&quot;&#34;
'Single quotation mark&apos;&#39;
 Non-breaking space&nbsp;&#160;
©Copyright symbol&copy;&#169;
®Registered trademark&reg;&#174;
Trademark symbol&trade;&#8482;
Euro sign&euro;&#8364;
£British Pound&pound;&#163;
¥Japanese Yen&yen;&#165;
×Multiplication sign&times;&#215;
÷Division sign&divide;&#247;
±Plus-minus sign&plusmn;&#177;
°Degree symbol&deg;&#176;
Heart symbol&hearts;&#9829;
Spade symbol&spades;&#9824;

Using &nbsp; – Non-Breaking Space

The &nbsp; entity inserts a space that will not collapse like regular spaces and will prevent the browser from wrapping text at that point.

<!-- Adding extra visible space between words -->
<p>Name:&nbsp;&nbsp;&nbsp;John Smith</p>
<p>Phone:&nbsp;&nbsp;+1 234 567 8900</p>

<!-- Keeping two words always together on one line -->
<p>Call us on&nbsp;Monday.</p>

Displaying HTML Tags as Text

When teaching HTML or documenting code, there is a need to show HTML tags as plain visible text rather than having the browser interpret them. Entities are used for this purpose.

<!-- To display: Use <h1> for the main heading -->
<p>Use &lt;h1&gt; for the main heading.</p>

<!-- To display: <a href="..."> -->
<p>Links use the &lt;a href="..."&gt; tag.</p>

Entities in Practice

<footer>
  <p>&copy; 2025 eStudy247. All rights reserved.</p>
</footer>

<p>Water boils at 100&deg;C.</p>

<p>Price: &euro;49.99 or &pound;42.00</p>

<p>5 &times; 8 = 40</p>

<p>HTML &amp; CSS are the building blocks of the web.</p>

Key Points to Remember

  • Use HTML entities to display characters that have special meaning in HTML
  • The most essential entities are &lt;, &gt;, and &amp;
  • All entities start with & and end with ;
  • Named entities (&copy;) are more readable than numeric entities (&#169;)
  • Use &nbsp; to add non-collapsible spaces or prevent line breaks
  • Entities are case-sensitive — &copy; works, &COPY; does not

Leave a Comment

Your email address will not be published. Required fields are marked *