HTML    Foundation  Questions: Entities

Foundation Bundle 1

Questions: HTML Entities

An HTML entity is a sequence of characters that altogether represent a single character in the final HTML output. It begins with an ampersand (&) and ends with a semicolon (;).

A character reference is basically just another name for an HTML entity.

  • Named entities (which use names to refer to given characters, for e.g. &lt; for the less-than, <, symbol).
  • Numeric entities (which use numeric codes to refer to given characters).

A named entity is an HTML entity with a name. That simple! Some common examples are &lt; (less-than, <), &gt; (greater-than, >), &nbsp; (non-breaking space), &rarr; (right arrow, ), &bullet; (bullet point, ), and so on and so forth.

&nbsp; denotes a non-breaking space in HTML.

The entities &lt; and &gt; represent the less-than (<) and greater-than (>) symbols in HTML, respectively. They are really common in HTML because otherwise representing < and > can mess up with actual markup (as < represents the beginning of an HTML tag).

Since the desired text contains the < character, which otherwise has a special meaning in HTML code (i.e. denotes an HTML tag's beginning), we must use the &lt; entity to denote it. Henceforth, the text '2 < 3' would be represented as follows:

HTML
2 &lt; 3

&amp;.

A numeric entity is an HTML entity containing a numeric code corresponding to the character that the entity denotes. Its general form For example, the < character corresponds to the numeric code 60 (in decimal). Likewise, we can denote it using the &#60; numeric entity.

A numeric entity can either be of the general form:

  • &#<code>;, where <code> denotes the numeric code corresponding to the character in decimal, or
  • &#x<code>;, where <code> denotes the numeric code in hexadecimal.

Decimal numeric entity: &#70;. Hexadecimal numeric entity: &#x46;.