Html Entity

From CSS Discuss

Jump to: navigation, search

Hyper Text Markup Language is a Standard Generalized Markup Language application, much as XHTML is an XML application.

SGML (and also, HTML) includes a mechanism for including arbitrary character sequences in markup, even when the characters would otherwise break the SGML format. This technique is often called "escaping" the illegal characters.

For example, in HTML, the "<" character has special meaning, and placing that character in the content (that is, not part of markup) of an HTML document is invalid.

In this case, you can use an entity reference.

Each entity reference starts with "&" and ends with ";". Everything in between is parsed as part of the entity reference.

There are two types of entity references:

  1. Numeric Entity Reference
  2. Character Entity Reference

Numeric Entities

Numeric entities are machine-readable references to the Nth code position in a document's character set.

A numeric entity reference can look like any of these:


The references "&#x3C" and "&#x003C" are hex representations of the same reference, and are equivalent to decimal 60.

Character Entities

Because it's unwieldy to remember character code positions, HTML also offers character entity references.

An example of a character entity reference is:


All four of the above examples equate to "<".

It's worth noting that some entities aren't supported very well in some browsers.


<a href="">This <and> That</a>

<a href=";That">This &lt;and&gt; That</a>

Further reading:

EVolt's "A Simple Entity Chart"
HTML Spec: Character References
Character entity references in HTML 4
Personal tools