In SGML, HTML and XML documents, the logical constructs known as character data and attribute values consist of sequences of characters, in which each character can manifest directly (representing itself), or can be represented by a series of characters called a character reference, of which there are two types: a numeric character reference and a character entity reference. This article lists the character entity references that are valid in HTML and XML documents.

Character reference overview

In HTML and XML, a numeric character reference refers to a character by its Universal Coded Character Set/Unicode code point, and uses the format:

&#xhhhh;

or

&#nnnn;

where the <code>x</code> must be lowercase in XML documents, hhhh is the code point in hexadecimal form, and nnnn is the code point in decimal form. The hhhh (or nnnn) may be any number of hexadecimal (or decimal) digits and may include leading zeros. The hhhh for hexadecimal digits may mix uppercase and lowercase letters, though uppercase is the usual style. However the XML and HTML standards restrict the usable code points to a set of valid values, which is a subset of UCS/Unicode code point values, that excludes all code points assigned to non-characters or to surrogates, and most code points assigned to C0 and C1 controls (with the exception of line separators and tabulations treated as white spaces).

By contrast, a character entity reference refers to a sequence of one or more characters by the name of an entity which has the desired characters as its replacement text. The format is: <code>&name;</code> where name is the case-sensitive name of the entity. The semicolon is usually required in the character entity reference, unless marked otherwise in the table below (see The HTML5 specification does not allow users to define additional entities, as it no longer accepts any DTD to be referenced or extended inside HTML documents (this is still needed in XHTML, which is based on stricter XML parsing rules but allows referencing or defining a DTD in the document header, because XML does not predefine most HTML entities).

In the below table, the "Standard" column indicates the first version of the HTML DTD that defines the character entity reference, and indicates characters that are predefined in XML without needing any DTD. To use one of these character entity references in an HTML or XML document, enter an ampersand (&) followed by the entity name, and a semicolon (mandatory in XML, and strongly recommended in HTML for all entities, even if HTML allows omitting the semicolon only from some entities indicated below by ).

However, all valid characters and sequences in the UCS, including all bidirectional controls or private-use assignments (but with the exception of non-whitespace C0 and C1 controls, non-characters, and surrogates) are also usable and valid in HTML, XML, XHTML and MathML, either in plain-text values of attributes or in text elements (by encoding them directly as plain text, or using numeric character references when needed).

{| class="wikitable sortable nounderlines sticky-header"

|+ style="font-size: 105%;" | All named character entity references in HTML and XML

|-

! scope="col" | Entities

! scope="col" |

! scope="col" | Codepoints

! scope="col" | Standard

! scope="col" | DTD HTML5 approximates them with the zero-width space.

| data-sort-value="&#x200B;" | <small style="background:#DDD;color:#222;border:1px dotted;padding:0 1px">ZWSP</small>

| data-sort-value="0:0:2:0:0:B" | U+200B

| HTML 5.0

|

|

| zero width space (negative space)

|-

|

| data-sort-value="&#x200C;" | <small style="background:#DDD;color:#222;border:1px dotted;padding:0 1px">ZWNJ</small>

| data-sort-value="0:0:2:0:0:C" | U+200C

| HTML 4.0

| HTMLspecial

| NEW RFC 2070

| zero width non-joiner

|-

|

| data-sort-value="&#x200D;" | <small style="background:#DDD;color:#222;border:1px dotted;padding:0 1px">ZWJ</small>

| data-sort-value="0:0:2:0:0:D" | U+200D

| HTML 4.0

| HTMLspecial

| NEW RFC 2070

| zero width joiner

|-

|

| data-sort-value="&#x200E;" | <small style="background:#DDD;color:#222;border:1px dotted;padding:0 1px">LRM</small>

| data-sort-value="0:0:2:0:0:E" | U+200E

| HTML 4.0

| HTMLspecial

| NEW RFC 2070

| left-to-right mark

|-

|

| data-sort-value="&#x200F;" | <small style="background:#DDD;color:#222;border:1px dotted;padding:0 1px">RLM</small>

| data-sort-value="0:0:2:0:0:F" | U+200F

| HTML 4.0

| HTMLspecial

| NEW RFC 2070

| right-to-left mark

|-

|

| ‐

| data-sort-value="0:0:2:0:1:0" | U+2010

| HTML 5.0

|

| ISOnum

| hyphen (Unicode hyphen)

|-

|

| –

| data-sort-value="0:0:2:0:1:3" | U+2013

| HTML 4.0

| HTMLspecial

| ISOpub

| en dash

|-

|

| —

| data-sort-value="0:0:2:0:1:4" | U+2014

| HTML 4.0

| HTMLspecial

| ISOpub

| em dash

|-

|

| ―

| data-sort-value="0:0:2:0:1:5" | U+2015

| HTML 5.0

|

| ISOnum

| horizontal bar

|-

|

| ‖

| data-sort-value="0:0:2:0:1:6" | U+2016

| HTML 5.0

|

| ISOtech

| double vertical line

|-

|

|

| data-sort-value="0:0:2:0:1:8" | U+2018

|

| HTMLspecial

| ISOnum

| left single quotation mark (open curly quote)

|-

|

|

| data-sort-value="0:0:2:0:1:9" | U+2019

|

| HTMLspecial

| ISOnum

| right single quotation mark (close curly quote)

|-

|

| ‚

| data-sort-value="0:0:2:0:1:A" | U+201A

|

| HTMLspecial

|

| single low-9 quotation mark (single baseline quote)

|-

|

|

| data-sort-value="0:0:2:0:1:C" | U+201C

|

| HTMLspecial

| ISOnum

| left double quotation mark (open curly double quote)

|-

|

|

| data-sort-value="0:0:2:0:1:D" | U+201D

|

| HTMLspecial

| ISOnum

| right double quotation mark (close curly double quote)

|-

|

| „

| data-sort-value="0:0:2:0:1:E" | U+201E

|

| HTMLspecial

|

| double low-9 quotation mark (baseline double quote)

|-

|

| †

| data-sort-value="0:0:2:0:2:0" | U+2020

| HTML 4.0

| HTMLspecial

| ISOpub

| dagger (obelisk)

|-

|

| ‡

| data-sort-value="0:0:2:0:2:1" | U+2021

|

| HTMLspecial

| ISOpub

| double dagger (double obelisk)

|-

|

| •

| data-sort-value="0:0:2:0:2:2" | U+2022

|

| HTMLspecial

| ISOpub

| bullet (black small circle) | HTML 5.0 | HTML 5.0 | HTML 5.0

| HTMLsymbol

| ISOamso

| black-letter capital I (Fraktur capital I, imaginary part)

|-

|

| ℒ

| data-sort-value="0:0:2:1:1:2" | U+2112

| HTML 5.0

|

| ISOmscr

| script capital L (Lagrangian mechanics, Laplace transform)

|-

|

| ℓ

| data-sort-value="0:0:2:1:1:3" | U+2113

| HTML 5.0

|

| ISOamso

| script small l (ell, a mathematical symbol)

|-

|

| ℕ

| data-sort-value="0:0:2:1:1:5" | U+2115

| HTML 5.0

|

| ISOmopf

| double-struck capital N (Natural number, open-face capital N)

|-

|

| №

| data-sort-value="0:0:2:1:1:6" | U+2116

| HTML 5.0

|

| ISOcyr1

| numero sign

|-

|

| ℗

| data-sort-value="0:0:2:1:1:7" | U+2117

| HTML 5.0

|

| ISOpub

| sound recording copyright; or phonogram copyright symbol

Entities representing special characters in XHTML

The XHTML DTDs explicitly declare 253 entities (including the 5 predefined entities of XML 1.0) whose expansion is a single character, which can therefore be informally referred to as "character entities". These (with the exception of the <code>&amp;apos;</code> entity) have the same names and represent the same characters as the 252 character entities in HTML&nbsp;4.0. Also, by virtue of being XML, XHTML documents may reference the predefined <code>&amp;apos;</code> entity, which is not one of the 252 character entities in HTML&nbsp;4.0. Additional entities of any size may be defined on a per-document basis. However, the usability of entity references in XHTML is affected by how the document is being processed:

  • Legacy abbreviated character entities (without the final colon) inherited from HTML&nbsp;2.0 (and still supported in HTML&nbsp;5.0) are not supported in XML 1.0 and XHTML; the trailing semicolon must be present in all entity references used in XML and XHTML documents.
  • If the XHTML document is read by a conforming HTML 4.0 processor, then only the 252 HTML&nbsp;4.0 character entities may safely be used. The use of <code>&amp;apos;</code> or custom entity references may not be supported and may produce unpredictable results (it is recommended to use the numerical character reference <code>&amp;#39;</code> instead).
  • If the document is read by an XML parser that does not or cannot read external entities, then only the five built-in XML character entities can safely be used, although other entities may be used if they are declared in the internal DTD subset. However, modern XML parsers recognize and implement a builtin cache for SGML references to DTDs used by all standard versions of HTML, XHTML, SVG and MathML, without needing to parse and process the external DTD via their URL and without needing to process entities defined in an internal DTD subset of the document.
  • If the document is read by an XML parser that does read external entities and does not implement a builtin cache for well-known DTDs, then the five built-in XML character entities (and numeric character references) can safely be used. The other 248 HTML character entities can be used as long as the XHTML DTD is accessible to the parser at the time the document is read. Other entities may also be used if they are declared in the internal DTD subset and the XML processor can parse internal DTD subsets.
  • HTML 5.0 parsers cannot process XHTML documents, and it's impossible to define a fully validating DTD for HTML5 documents encoded with the XHTML syntax (notably it's impossible to validate all attributes names, notably "data-*" attributes); as well it's still impossible to fully validate (with W3C standard schemas for XML, such as XSD or relax NG) HTML5 documents represented in the XHTML syntax, and for now a custom validator specific to HTML 5.0 is required.

Because of the special <code>&amp;apos;</code> case mentioned above, only <code>&amp;quot;</code>, <code>&amp;amp;</code>, <code>&amp;lt;</code>, and <code>&amp;gt;</code> will work in all XHTML processing situations.

See also

  • Character encodings in HTML
  • Digraph and Trigraph, a similar concept to enter unavailable characters
  • Escape character
  • HTML decimal character rendering
  • Percent-encoding, used in URLs
  • SGML entity

References

Further reading

  • Unicode Consortium. See also: Unicode Consortium
  • UnicodeData.txt from the Unicode Consortium
  • World Wide Web Consortium. See also: World Wide Web Consortium
  • XML 1.0 spec
  • HTML 2.0 spec
  • HTML 3.2 spec
  • HTML 4.0 spec
  • HTML 4.01 spec
  • HTML 5 spec
  • XHTML 1.0 spec
  • XML Entity Definitions for Characters
  • The normative reference to RFC 2070 (still found in DTDs defining the character entities for HTML or XHTML) is historic; this RFC (along with other RFC's related to different part of the HTML specification) has been deprecated in favor of the newer informational RFC 2854 which defines the "text/html" MIME type and references directly the W3C specifications for the actual HTML content.
  • Numerical Reference of Unicode code points at Wikibooks
  • W3 HTML5 Character Reference Chart
  • Character entity references in HTML 4 at the W3C
  • Webpage for encoding and decoding special characters