Character_entity_reference

List of XML and HTML character entity references

List of XML and HTML character entity references

Add article description


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.

A character entity reference refers to the content of a named entity. An entity declaration is created in XML, SGML and HTML documents (before HTML5) by using the <!ENTITY name "value"> syntax in a Document type definition (DTD).

Character reference overview

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

&#xhhhh;

or

&#nnnn;

where the x 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).

In 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 entity must either be predefined (built into the markup language), or otherwise explicitly declared in a Document Type Definition (DTD) (see [lower-alpha 1]). The format is the same as for any entity reference:

&name;

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 [lower-alpha 2]).

Standard public entity sets for characters

XML
XML specifies five predefined entities needed to support every printable ASCII character: &amp;, &lt;, &gt;, &apos;, and &quot;. The trailing semicolon is mandatory in XML (and XHTML) for these five entities (even if HTML or SGML allows omitting it for some of them, according to their DTD).
ISO Entity Sets
SGML supplied a comprehensive set of entity declarations for characters widely used in Western technical and reference publishing, for Latin, Greek and Cyrillic scripts. The American Mathematical Society also contributed entities for mathematical characters (see [lower-alpha 3]).
HTML Entity Sets
Early versions of HTML built in small subsets of these, relating to characters found in three Western 8-bit fonts.
MathML Entity Sets
The W3C developed a set of entity declarations for MathML characters.
XML Entity Sets
The W3C MathML Working Group took over maintenance of the ISO public entity sets, combined with the MathML and documents them in XML Entity Definitions for Characters. This set can support the requirements of XHTML, MathML and as an input to future versions of HTML.
HTML5
HTML5 adopts the XML entities as named character references, however it restates them without reference to their sources and does not group them into sets. The HTML5 specification additionally provides mappings from the names to Unicode character sequences using JSON.

Numerous other entity sets have been developed for special requirements, and for major and minority scripts. However, the advent of Unicode has largely superseded them.

List of character entity references in HTML

HTML5 defines many named entities, references to which act as mnemonic aliases for certain Unicode characters.[1]  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 [lower-alpha 2]), e.g., enter &copy; for the copyright symbol ©.

There are no predefined character entities in HTML for characters or sequences of most scripts encoded in the UCS (except a common subset of whitespace, punctuation, mathematical or technical symbols, currency symbols, a few Hebrew symbols used in mathematical notations, and the most common letters in Latin, Greek or Cyrillic).  Note also that not all bidirectional controls defined in UCS/Unicode are represented as standard character entities in HTML (not even in HTML5, which defines more general directional elements and attributes for that purpose).  Notably, there are no predefined HTML character entities for controls that were added in the UCS/Unicode and formally defined in version 2 of the Unicode Bidi Algorithm.

Most entities are predefined in XML and HTML to reference just one character in the UCS, but there are no predefined entities for isolated combining characters, variation selectors, or characters for private use assignments; however the list includes some predefined entities for character sequences of two characters containing some of them.  Since HTML 5.0 (and MathML 3.0 which shares the same set en entities), all entities are encoded in Unicode normalization forms C and KC (this was not the case with older versions of HTML and MathML, so older entities that were initially defined with characters for private use assignments, CJK compatiblity forms, or in non-NFC forms were modified[2]).

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).

More information Entities, Char. ...
Notes
  1. DTD: the full public DTD name (where the character entity name is defined) is actually mapped from one of the following three defined named entities:
    • HTMLlat1 maps to:
    • HTMLsymbol maps to:
    • HTMLspecial maps to:
    • doc.dtd refers to:
    • there's no DTD for HTML 5.0 (and also no ISO subset), whose all entities are predefined. The HTML 5.0 parser does not allow and support the dangerous old SGML parser for DTDs that was used in HTML 4 and before. Limited attempts to map HTML 5.0 to XHTML (i.e. with the XML parser that supports SGML DTDs) have been experimented privately, but it is impossible to strictly validate in XML the schema needed for HTML 5.0, without also defining custom XSD's (at least for the custom "data-*" attributes). The best way to securely interchange HTML5 with XHTML is to convert all entity references to plain-text, or to numerical character references, or to the 5 standard entities of XML 1.0, without including any DTD.
  2. The trailing semicolon may be omitted for this named entity.
  3. Old ISO subset: these are old (documented) character subsets used in legacy encodings before the unification within ISO 10646.
  4. Description: the standard ISO 10646 and Unicode character name is displayed first for each character, with non-standard but legacy synonyms shown in italics between parentheses after an equal sign.
  5. The leading space before combining characters used in old DTDs for MathML2.0 was removed in MathML 3.0 and HTML 5.0.
  6. &quot; was omitted from the HTML 3.2 specification, but was restored as of HTML 4.0. In practice, most web browsers displaying HTML 3.2 pages render it as if it had been included in the spec.
  7. spaces: a blue background is used to display each space's width.
  8. &copy;: U+00A9 'copyright symbol' is not the same as U+24B8 'circled Latin capital letter C', although the same glyph could be used do depict both characters. See also U+24D2 'Latin small letter c'.
  9. &reg;: U+00AE 'registered sign' is not the same as U+24C7 'circled Latin capital letter R', although the same glyph could be used do depict both characters.
  10. &angst;: The use of U+212B 'Angstrom sign', which was encoded due to round-trip mapping compatibility with an East-Asian character encoding, is discouraged, and the preferred representation is U+00C5 'capital letter A with ring above', which has the same glyph.
  11. &IJlig; and &ijlig;: The use of U+0132 'IJ ligature' or U+0133 'ij ligature', which were encoded for usage in Dutch and for compatibility for ISO/IEC 6937 and Code page 1102 (which only includes the lowercase ij, also part of the Dutch version of ISO 646 National Replacement Character Set), is discouraged, and the preferred representation is simply 'IJ' or 'ij' (as two separate letters).
  12. &lmidot;: The use of U+013F 'Latin small letter l with middle dot' or U+0140 'Latin capital letter L with middle dot', which were encoded for usage in Catalan and for compatibility for ISO/IEC 6937, is discouraged, and the preferred representation is 'L' or 'l', followed by U+00B7.
  13. &napos;: The use of U+0149 'n preceded by apostrophe', which was encoded for usage in Afrikaans and for compatibility for ISO/IEC 6937, has been deprecated by Unicode (since Unicode 5.2), and the preferred representation is ʼn (U+02BC followed by n). (Unicode.org - Proposal for Additional Deprecated Characters).
  14. ligature: this is a standard misnomer as this is a separate character in some languages.
  15. &ohm;: The use of U+2126 'ohm sign', is discouraged, and the preferred representation is U+03A9 'Greek capital letter Omega', which has the same glyph.
  16. black: here it seems to mean filled as opposed to hollow.
  17. ISO proposed: these characters have been standardized in ISO 10646 after the release of HTML 4.0.
  18. &copysr;: U+2117 'sound recording copyright' is not the same as U+24C5 'circled Latin capital letter P', although the same glyph could be used do depict both characters.
  19. &alefsym;: U+2135 'alef symbol' is not the same as U+05D0 'Hebrew letter alef', although the same glyph could be used to depict both characters.
  20. &beth;: U+2136 'bet symbol' is not the same as U+05D1 'Hebrew letter bet', although the same glyph could be used to depict both characters.
  21. &gimel;: U+2137 'gimel symbol' is not the same as U+05D2 'Hebrew letter gimel', although the same glyph could be used to depict both characters.
  22. &daleth;: U+2138 'dalet symbol' is not the same as U+05D3 'Hebrew letter dalet', although the same glyph could be used to depict both characters.
  23. &lArr;: ISO 10646 does not say that 'leftwards double arrow' is the same as the 'is implied by' arrow, but also does not have any other character for that function, so lArr can be used for 'is implied by' as ISOtech suggests.
  24. &rArr;: ISO 10646 does not say that 'rightwards double arrow' is the same as the 'implies' arrow, but also does not have any other character with this function, so rArr can be used for 'implies' as ISOtech suggests.
  25. &prod;: U+220F 'n-ary product' is not the same character as U+03A0 'Greek capital letter Pi' though the same glyph might be used for both.
  26. &sum;: U+2211 'n-ary summation' is not the same character as U+03A3 'Greek capital letter Sigma' though the same glyph might be used for both.
  27. &sim;: U+223C 'tilde operator' is not the same character as U+007E 'tilde', although the same glyph might be used to represent both.
  28. &nsup;: U+2285 'not a superset of' is in the 'ISOamsn' subset, but is not covered by the Symbol font encoding, and is not listed in the HTML 4.0 entities list on the documentation, where it was erroneously omitted; it should be included for symmetry and analogy with other entities.
  29. &perp;: Unicode only defines U+22A5 as the "up tack", and the Unicode symbol for "perpendicular" is U+27C2: the two symbols look similar, but are separate in Unicode. However, HTML uses U+22A5 as its "perpendicular" symbol: this is a discrepancy between HTML and Unicode. As well, the U+22A4 character (the "down tack" symbol) rendered in a browser such as Firefox 3.6 can match the font of either "up tack" or "perpendicular", but not both, depending on whether a fixed-width or a proportional font is used. When viewed in Firefox 3.6, the symbols rendered in the order U+22A5, U+22A4, U+27C2 in a proportional font: "⊥ ⊤ ⟂" and a fixed width one: ⊥ ⊤ ⟂, shows that the "down tack" has a similar look to U+22A5 (HTML's "perpendicular") in the first case but matches U+27C2 in the second. This exemplifies the difficulties of the semiotics involved in interpreting glyphs, symbols and characters generally.
  30. &sdot;: U+22C5 'dot operator' is not the same character as U+00B7 'middle dot'.
  31. &Ll;: U+22D8 'very much less-than' is missing in the HTML 5.2 list of entities, where it was omitted.
  32. &lang;: U+27E8 'mathematical left angle bracket' is not the same character as U+003C 'less than', U+2039 'single left-pointing angle quotation mark', or U+3008 'left angle bracket'. In HTML 5.0, lang was remapped to this code, as U+2329 'left-pointing angle bracket' has been marked deprecated in Unicode (since version 5.2) (Unicode.org - Proposal for Additional Deprecated Characters).
  33. &rang;: U+27E9 'mathematical right angle bracket' is not the same character as U+003E 'greater than', U+203A 'single right-pointing angle quotation mark', or U+3009 'right angle bracket'. In HTML 5.0, rang had been remapped to this code, as U+232A 'right-pointing angle bracket' has been marked deprecated in Unicode (since version 5.2) (Unicode.org - Proposal for Additional Deprecated Characters).

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 &apos; entity) have the same names and represent the same characters as the 252 character entities in HTML 4.0. Also, by virtue of being XML, XHTML documents may reference the predefined &apos; entity, which is not one of the 252 character entities in HTML 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:[citation needed]

  • Legacy abbreviated character entities (without the final colon) inherited from HTML 2.0 (and still supported in HTML 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 4.0 character entities may safely be used. The use of &apos; or custom entity references may not be supported and may produce unpredictable results (it is recommended to use the numerical character reference &#39; 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.[citation needed]
  • 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 &apos; case mentioned above, only &quot;, &amp;, &lt;, and &gt; will work in all XHTML processing situations.

See also


References

  1. "HTML5 Named Character Reference List".

Further reading


Share this article:

This article uses material from the Wikipedia article Character_entity_reference, and is written by contributors. Text is available under a CC BY-SA 4.0 International License; additional terms may apply. Images, videos and audio are available under their respective licenses.