HTML Entities

In this tutorial, we will learn about entities in HTML with the help of examples.

The HTML entities are used to display reserved characters (characters that are used in HTML code), special characters, or invisible characters. For example,

<p>This is a &lt;p&gt; tag.</p> 

Browser Output

HTML Entities

Here, &lt; and &gt; are the HTML entities used to display < and > respectively.

If we were to use the <p> tag instead of &lt;p&gt; the browser would read it as a tag. Hence to display <p> we need to use &lt; and &gt; instead of < and > respectively.


HTML Entities Syntax

HTML entities are represented by either their name or their number.

  • Entity names

We use &entity_name; to add reserved characters using Entity names. For example,
&cent; would be displayed as ¢

  • Entity number

We use &#entity_number; to add reserved characters using Entity number. For example, &#162; would also be displayed as ¢

All entity names and numbers start with an & and end with an ;.

Note: Not all entities have names, only characters that are commonly used have entity names.


Special Characters

Special characters are characters that are not available on a general keyboard like ®, ©, ¢, etc.
We use HTML entities to add special characters to HTML documents. For example

<footer> &copy; 2022 Programiz. All rights reserved. </footer>

Browser Output

Copyright Symbol Example

Invisible Characters

An invisible character is a character that is not visible when rendered in a document or text field. These characters can be used for various purposes, such as adding white space or formatting a document. For example,

<p>Invi<span>&zwnj;</span>sible<span>&nbsp;</span>Cha<span>&zwnj;</span>racters</p>

Browser Output

Here, &zwnj; and &nbsp; are invisible characters. &zwnj; is a zero-width character whereas &nbsp; is a space character.

Some examples of invisible characters are – space, tab, zero-width space, etc.


Some important HTML entities

Character(s) Literal(s) Alphanumeric value(s) Unicode value(s)
Cent (currency) ¢ &cent; &#162;
Pound (currency) £ &pound; &#163;
Section § &sect; &#167;
Copyright © &copy; &#169;
Guillemets « » &laquo; &raquo; &#171; &#187;
Registered trademark ® &reg; &#174;
Degree(s) ° &deg; &#176;
Plus/minus ± &plusmn; &#177;
Pilcrow (paragraph) &para; &#182;
Middle dot · &middot; &#183;
Fractional half ½ &frac12; &#188;
En dash &ndash; &#8211;
Em (long) dash &mdash; &#8212;
Single quotes ' ' &lsquo; &rsquo; &#8216; &#8217;
Single low quote &sbquo; &#8218;
Double quotes " " &ldquo; &rdquo; &#8220; &#8221;
Double low quote &bdquo; &#8222;
Single & double daggers † ‡ &dagger; &Dagger; &#8224; &#8225;
Bullet &bull; &#8226;
Ellipsis &hellip; &#8230;
Prime & double prime ′ ″ &prime; &Prime; &#8242; &#8243;
Euro sign &euro; &#8364;
Trademark &trade; &#8482;
Almost equal to &asymp; &#8776;
Not equal to &ne; &#8800;
Less/greater than or equal to &le; &ge; &#8804; &#8805;
Less/greater than < > &lt; &gt; &#062; &#060;