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 by using the <!ENTITY name "value">
syntax in a Document Type Definition (DTD).
Character reference overview
List of XML and HTML character entity references - 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 , or can...
A numeric character reference refers to a character by its Universal Character Set/Unicode code point, and uses the format:
&#
nnnn;
or
&#x
hhhh;
where nnnn is the code point in decimal form, and hhhh is the code point in hexadecimal form. The x must be lowercase in XML documents. The nnnn or hhhh may be any number of digits and may include leading zeros. The hhhh may mix uppercase and lowercase, though uppercase is the usual style.
In contrast, a character entity reference refers to a character by the name of an entity which has the desired character as its replacement text. The entity must either be predefined (built into the markup language) or explicitly declared in a Document Type Definition (DTD). The format is the same as for any entity reference:
&
name;
where name is the case-sensitive name of the entity. The semicolon is required.
Standard public entity sets for characters
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.
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.
HTML 5: 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 HTML 5 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.
Predefined entities in XML
The XML specification does not use the term "character entity" or "character entity reference". The XML specification defines five "predefined entities" representing special characters, and requires that all XML processors honor them. The entities can be explicitly declared in a DTD, as well, but if this is done, the replacement text must be the same as the built-in definitions. XML also allows other named entities of any size to be defined on a per-document basis.
The table below lists the five XML predefined entities. The "Name" column mentions the entity's name. The "Character" column shows the character. To render the character, the format &name;
is used; for example, &
renders as &. The "Unicode code point" column cites the character via standard UCS/Unicode "U+" notation, which shows the character's code point in hexadecimal. The decimal equivalent of the code point is then shown in parentheses. The "Standard" column indicates the first version of XML that includes the entity. The "Description" column cites the character via its canonical UCS/Unicode name, in English.
Character entity references in HTML
The HTML 4 DTDs define 252 named entities, references to which act as mnemonic aliases for certain Unicode characters. The HTML 4 specification requires the use of the standard DTDs and does not allow users to define additional entities.
In the table below, the "Standard" column indicates the first version of the HTML DTD that defines the character entity reference. HTML 4.01 does not provide any new character references.
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, e.g., &
for the ampersand ("&").
Notes:
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 '
entity) have the same names and represent the same characters as the 252 character entities in HTML. Also, by virtue of being XML, XHTML documents may reference the predefined '
entity, which is not one of the 252 character entities in HTML. 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:
- If the document is read by a conforming HTML processor, then only the 252 HTML character entities can safely be used. The use of
'
or custom entity references may not be supported and may produce unpredictable results. - 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 (see above) can safely be used, although other entities may be used if they are declared in the internal DTD subset.
- If the document is read by an XML parser that does read external entities, then the five built-in XML character entities 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.
Because of the special '
case mentioned above, only "
, &
, <
, and >
will work in all processing situations.
See also
- Character encodings in HTML
- HTML decimal character rendering
- SGML entity
- Digraph and Trigraph (a similar concept to enter unavailable characters)
References
- 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
External links
- Character entity references in HTML 4 at the W3C
- Webpage for encoding and decoding special characters