What Is an HTML Entity?

Find out all about HTML entities

An HTML entity is a text/string that represents:

  • Reserved characters (which would otherwise be interpreted as HTML code), and;
  • Invisible characters (such as non-breaking spaces, etc.).

An HTML entity begins with an ampersand (&) and ends with a semi-colon (;). For example, to display the copyright symbol (i.e. ©) you can use the following HTML entity codes:

<!-- using named reference -->
&copy;
<!-- using decimal char code -->
&#169;
<!-- using hexadecimal char code -->
&#xA9;

As you can see from the examples above, HTML entities can be in the following three forms:

  1. Named character reference;
  2. Numeric character reference in decimal;
  3. Numeric character reference in hexadecimal.

Using a Named Character Reference

A named character reference has the following syntax:

&named_ref;

You can use named character references for most common characters. However, for those characters for which there is no supported named reference, you can use numeric character reference instead (either in decimal or hexadecimal form).

For example:

<!-- less than sign -->
&lt;
<!-- greater than sign -->
&gt;
<!-- non-breaking space -->
&nbsp;

Using a Numeric Character Reference in Decimal

A numeric character reference in decimal has the following syntax:

&#nnnn;

Where nnnn is the character's Unicode/UCS code point in decimal form.

For example:

<!-- less than sign -->
&#60;
<!-- greater than sign -->
&#62;
<!-- non-breaking space -->
&#160;
<!-- beaming face with smiling eyes emoji -->
&#128513;

Using a Numeric Character Reference in Hexadecimal

A numeric character reference in hexadecimal has the following syntax:

&#xhhhh;

Where:

  • x is used to indicate that all subsequent characters should be interpreted as hexadecimal, and;
  • hhhh is the character's Unicode/UCS code point in hexadecimal form.

For example:

<!-- less than sign -->
&#x3C;
<!-- greater than sign -->
&#x3E;
<!-- non-breaking space -->
&#xA0;
<!-- beaming face with smiling eyes emoji -->
&#x1F601;

Hope you found this post useful. It was published . Please show your love and support by sharing this post.