Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Numeric character reference
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Common markup construct used in SGML, XML, and HTML}} {{one source|date=February 2021}} A '''numeric character reference''' ('''NCR''') is a common [[markup (computer programming)|markup]] construct used in [[SGML]] and SGML-derived markup languages such as [[HTML]] and [[XML]]. It consists of a short sequence of [[character (computing)|character]]s that, in turn, represents a single character. Since [[SGML|WebSgml]], [[XML]] and [[HTML 4]], the code points of the [[Universal Character Set]] (UCS) of [[Unicode]] are used. NCRs are typically used in order to represent characters that are not [[plain text#Encoding|directly encodable]] in a particular document (for example, because they are international characters that do not fit in the 8-bit [[Character encoding|character set]] being used, or because they have special syntactic meaning in the language). When the document is interpreted by a markup-aware reader, each NCR is treated as if it were the character it represents. ==Examples== In SGML, HTML, and XML, the following are all valid numeric character references for the Greek capital letter Sigma {| class="wikitable" |+ Numerical character reference of {{unichar|03A3|GREEK CAPITAL LETTER SIGMA}}<br/>({{hexadecimal|0931}} = 931<sub>10</sub>) |- ! [[Unicode#Upluslink|Unicode character]] ! Numerical base ! Numerical reference in markup ! Effect |- | U+03A3 || Decimal || &#931; || Ξ£ |- | U+03A3 || Decimal || &#0931; || Ξ£ |- | U+03A3 || Hexadecimal || &#x3A3; || Ξ£ |- | U+03A3 || Hexadecimal || &#x03A3; || Ξ£ |- | U+03A3 || Hexadecimal || &#x3a3; || Ξ£ |} In SGML, HTML, and XML, the following are all valid numeric character references for the Latin capital letter AE {| class="wikitable" |+ Numerical character reference of {{unichar|00C6|Latin capital letter AE}} |- ! [[Unicode#Upluslink|Unicode character]] ! Numerical base ! Numerical reference in markup ! Effect |- | U+00C6 || Decimal || &#198; || Γ |- | U+00C6 || Hexadecimal || &#xC6; || Γ |} In SGML, HTML, and XML, the following are all valid numeric character references for the Latin small letter sharp s Γ {| class="wikitable" |+ Numerical character reference of {{unichar|00DF|Latin small letter sharp s}} |- ! [[Unicode#Upluslink|Unicode character]] ! Numerical base ! Numerical reference in markup ! Effect |- | U+00DF || Decimal || &#223; || Γ |- | U+00DF || Hexadecimal || &#xDF; || Γ |} List of numeric character references for the printable [[ASCII]] characters: {| class="wikitable" ! [[Unicode#Upluslink|Unicode character]] ! Character<br />Reference<br />(decimal) ! Character<br />Reference<br />(hexadecimal) ! Effect |- | U+0020 || &#32; || &#x20; || (space) |- | U+0021 || &#33; || &#x21; || ! |- | U+0022 || &#34; || &#x22; || " |- | U+0023 || &#35; || &#x23; || # |- | U+0024 || &#36; || &#x24; || $ |- | U+0025 || &#37; || &#x25; || % |- | U+0026 || &#38; || &#x26; || & |- | U+0027 || &#39; || &#x27; || ' |- | U+0028 || &#40; || &#x28; || ( |- | U+0029 || &#41; || &#x29; || ) |- | U+002A || &#42; || &#x2A; || * |- | U+002B || &#43; || &#x2B; || + |- | U+002C || &#44; || &#x2C; || , |- | U+002D || &#45; || &#x2D; || - |- | U+002E || &#46; || &#x2E; || . |- | U+002F || &#47; || &#x2F; || / |- | U+0030 || &#48; || &#x30; || 0 |- | U+0031 || &#49; || &#x31; || 1 |- | U+0032 || &#50; || &#x32; || 2 |- | U+0033 || &#51; || &#x33; || 3 |- | U+0034 || &#52; || &#x34; || 4 |- | U+0035 || &#53; || &#x35; || 5 |- | U+0036 || &#54; || &#x36; || 6 |- | U+0037 || &#55; || &#x37; || 7 |- | U+0038 || &#56; || &#x38; || 8 |- | U+0039 || &#57; || &#x39; || 9 |- | U+003A || &#58; || &#x3A; || : |- | U+003B || &#59; || &#x3B; || ; |- | U+003C || &#60; || &#x3C; || < |- | U+003D || &#61; || &#x3D; || = |- | U+003E || &#62; || &#x3E; || > |- | U+003F || &#63; || &#x3F; || ? |- | U+0040 || &#64; || &#x40; || @ |- | U+0041 || &#65; || &#x41; || A |- | U+0042 || &#66; || &#x42; || B |- | U+0043 || &#67; || &#x43; || C |- | U+0044 || &#68; || &#x44; || D |- | U+0045 || &#69; || &#x45; || E |- | U+0046 || &#70; || &#x46; || F |- | U+0047 || &#71; || &#x47; || G |- | U+0048 || &#72; || &#x48; || H |- | U+0049 || &#73; || &#x49; || I |- | U+004A || &#74; || &#x4A; || J |- | U+004B || &#75; || &#x4B; || K |- | U+004C || &#76; || &#x4C; || L |- | U+004D || &#77; || &#x4D; || M |- | U+004E || &#78; || &#x4E; || N |- | U+004F || &#79; || &#x4F; || O |- | U+0050 || &#80; || &#x50; || P |- | U+0051 || &#81; || &#x51; || Q |- | U+0052 || &#82; || &#x52; || R |- | U+0053 || &#83; || &#x53; || S |- | U+0054 || &#84; || &#x54; || T |- | U+0055 || &#85; || &#x55; || U |- | U+0056 || &#86; || &#x56; || V |- | U+0057 || &#87; || &#x57; || W |- | U+0058 || &#88; || &#x58; || X |- | U+0059 || &#89; || &#x59; || Y |- | U+005A || &#90; || &#x5A; || Z |- | U+005B || &#91; || &#x5B; || [ |- | U+005C || &#92; || &#x5C; || \ |- | U+005D || &#93; || &#x5D; || ] |- | U+005E || &#94; || &#x5E; || ^ |- | U+005F || &#95; || &#x5F; || _ |- | U+0060 || &#96; || &#x60; || ' |- | U+0061 || &#97; || &#x61; || a |- | U+0062 || &#98; || &#x62; || b |- | U+0063 || &#99; || &#x63; || c |- | U+0064 || &#100; || &#x64; || d |- | U+0065 || &#101; || &#x65; || e |- | U+0066 || &#102; || &#x66; || f |- | U+0067 || &#103; || &#x67; || g |- | U+0068 || &#104; || &#x68; || h |- | U+0069 || &#105; || &#x69; || i |- | U+006A || &#106; || &#x6A; || j |- | U+006B || &#107; || &#x6B; || k |- | U+006C || &#108; || &#x6C; || l |- | U+006D || &#109; || &#x6D; || m |- | U+006E || &#110; || &#x6E; || n |- | U+006F || &#111; || &#x6F; || o |- | U+0070 || &#112; || &#x70; || p |- | U+0071 || &#113; || &#x71; || q |- | U+0072 || &#114; || &#x72; || r |- | U+0073 || &#115; || &#x73; || s |- | U+0074 || &#116; || &#x74; || t |- | U+0075 || &#117; || &#x75; || u |- | U+0076 || &#118; || &#x76; || v |- | U+0077 || &#119; || &#x77; || w |- | U+0078 || &#120; || &#x78; || x |- | U+0079 || &#121; || &#x79; || y |- | U+007A || &#122; || &#x7A; || z |- | U+007B || &#123; || &#x7B; || { |- | U+007C || &#124; || &#x7C; || {{pipe}} |- | U+007D || &#125; || &#x7D; || } |- | U+007E || &#126; || &#x7E; || ~ |} ==Discussion== Markup languages are typically defined in terms of UCS or Unicode characters. That is, a document consists, at its most fundamental level of abstraction, of a sequence of characters, which are abstract units that exist independently of any [[character encoding|encoding]]. Ideally, when the characters of a document utilizing a markup language are encoded for storage or transmission over a network as a sequence of [[bit]]s, the encoding that is used will be one that supports representing each and every character in the document, if not in the whole of Unicode, directly as a particular bit sequence. Sometimes, though, for reasons of convenience or due to technical limitations, documents are encoded with an encoding that cannot represent some characters directly. For example, the widely used encodings based on [[ISO 8859]] can only represent, at most, 256 unique characters as one 8-bit [[byte]] each. Documents are rarely, in practice, ever allowed to use more than one encoding internally, so the onus is usually on the markup language to provide a means for document authors to express unencodable characters in terms of encodable ones. This is generally done through some kind of [[escape character|"escaping" mechanism]]. The SGML-based markup languages allow document authors to use special sequences of characters from the ASCII range (the first 128 code points of Unicode) to represent, or ''reference'', any Unicode character, regardless of whether the character being represented is directly available in the document's encoding. These special sequences are ''character references''. Character references that are based on the referenced character's UCS or Unicode [[code point]] are called ''numeric'' character references. In HTML 4 and in all versions of [[XHTML]] and XML, the code point can be expressed either as a [[decimal]] (base 10) number or as a [[hexadecimal]] (base 16) number. The syntax is as follows: Character U+0026 ([[ampersand]]), followed by character U+0023 ([[number sign]]), followed by one of the following choices: * one or more decimal digits zero (U+0030) through nine (U+0039); or * character U+0078 ("x") followed by one or more hexadecimal digits, which are zero (U+0030) through nine (U+0039), Latin capital letter A (U+0041) through F (U+0046), and Latin small letter a (U+0061) through f (U+0066); all followed by character U+003B ([[semicolon]]). Older versions of HTML disallowed the hexadecimal syntax. The characters that comprise a numeric character reference can be represented in every character encoding used in computing and telecommunications today, so there is no risk of the reference itself being unencodable. There is another kind of character reference called a ''[[character entity reference]]'', which allows a character to be referred to by a name instead of a number. (Naming a character creates a ''character [[SGML entity|entity]]''.) HTML defines some character entities, but not many; all other characters can only be included by direct encoding or using NCRs. ==Restrictions== The Universal Character Set defined by ISO 10646 is the "document character set" of SGML, HTML 4, so by default, any character in such a document, and any character ''referenced'' in such a document, must be in the UCS. While the syntax of SGML does not prohibit references to invalid or unassigned code points, such as <code>&#xFFFF;</code>, SGML-derived markup languages such as HTML and XML can, and often do, restrict numeric character references to only those code points that are assigned to characters. Restrictions may also apply for other reasons. For example, in HTML 4, <code>&#12;</code>, which is a reference to a non-printing "form feed" control character, is allowed because a form feed character is allowed. But in XML, the form feed character cannot be used, not even by reference.<ref>{{cite web |title=HTML 5.2: 8. The HTML syntax |url=https://www.w3.org/TR/2017/WD-html52-20170228/syntax.html |website=www.w3.org}}</ref>{{Citation needed|date=May 2013}} As another example, <code>&#128;</code>, which is a reference to another control character, is not allowed to be used or referenced in either HTML or XML, but when used in HTML, it is usually not flagged as an error by web browsers β some of which interpret it as a reference to the character represented by code value 128 in the [[Windows-1252]] encoding for compatibility reasons. This character, "β¬", has to be represented as <code>&#8364;</code> in a standard-compliant HTML code. As a further example, prior to the publication of XML 1.0 Second Edition on October 6, 2000, XML 1.0 was based on an older version of ISO 10646 and prohibited using characters above U+FFFD, except in character data, thus making a reference like <code>&#65536;</code> (U+10000) illegal. In XML 1.1 and newer editions of XML 1.0, such a reference is allowed, because the available character repertoire was explicitly extended. Markup languages also place restrictions on where character references can occur. ==Compatibility issues== In the initial versions of [[SGML]] and [[HTML]], numeric character references were interpreted in relationship to the document character encoding, rather than [[Unicode]]. For Latin-script documents, numeric character references to characters between x80 and x9F in those documents will not be correct against [[Unicode]], and must be recoded. HTML standards prior to [[HTML 4]] supported only Western Latin script documents: the treatment of character references above #7F may vary between applications and national conventions. For example, as mentioned above, the correct numeric character reference for the [[Euro sign]] "β¬" <code>U+20AC</code> when using [[Unicode]] is decimal <code>&#8364;</code> and hexadecimal <code>&#x20AC;</code>. However, if using tools supporting obsolete implementations of HTML, the reference <code>&#128;</code> (Euro sign in the [[CP-1252]] code page) or <code>&#164;</code> (Euro sign in [[ISO/IEC 8859-15]]) may work. As another example, if some text was created originally using the [[MacRoman]] character set, the [[quotation mark|left double quotation mark]] {{char|"}} will be represented with code point xD2. This will not display properly in a system expecting a document encoded as UTF-8, ISO 8859-1, or CP-1252, where this code point is occupied by the letter [[Γ]]. The correct numeric character reference for {{char|"}} in HTML 4 and newer is <code>&#x201C;</code>, because [[Unicode#Upluslink|U+]]201C is its UCS code. In some systems, the [[List of XML and HTML character entity references|named character reference]] <code>&ldquo;</code> may also be available. ==See also== * [[List of XML and HTML character entity references]] ==References== {{Reflist}} {{Unicode navigation}} {{DEFAULTSORT:Numeric Character Reference}} [[Category:HTML]] [[Category:Unicode]] [[Category:XML]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Char
(
edit
)
Template:Citation needed
(
edit
)
Template:Cite web
(
edit
)
Template:Hexadecimal
(
edit
)
Template:One source
(
edit
)
Template:Pipe
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)
Template:Unichar
(
edit
)
Template:Unicode navigation
(
edit
)