XML Character References: Decimal and Hex
XML character references are markup constructs used to represent individual Unicode characters through their unique numeric code points rather than their literal glyphs. This article explains what character references are, why they are used to handle special or reserved characters in XML documents, and how to properly format and apply both decimal and hexadecimal representations in your code.
What is an XML Character Reference?
A character reference is a way to include any legal Unicode character
in an XML document by referencing its Unicode code point. They are
particularly useful for: - Inserting characters that are difficult or
impossible to type on a standard keyboard (such as foreign language
glyphs, mathematical symbols, or typographic marks). - Preventing XML
parser errors caused by characters that conflict with XML syntax (like
< or &). - Ensuring document
portability across systems that use different text encodings.
All numeric character references begin with an ampersand and a hash
symbol (&#) and end with a semicolon
(;).
Decimal Character References
Decimal character references represent a character’s Unicode code point in base-10 format.
Syntax
&#[decimal_value];How to Use Decimal References
- Find the decimal Unicode code point for the target character.
- Place the decimal number directly after
&#and close it with;.
Examples
Copyright Symbol (
©): The decimal code point is 169.<notice>Copyright © 2024</notice>Ampersand (
&): The decimal code point is 38.<company>Smith & Sons</company>Euro Sign (
€): The decimal code point is 8364.<price>€50.00</price>
Hexadecimal Character References
Hexadecimal character references represent a character’s Unicode code
point in base-16 format. This is often the preferred form because
standard Unicode charts typically list code points in hexadecimal
notation (e.g., U+00A9).
Syntax
&#x[hexadecimal_value];Note: A lowercase x must precede the hexadecimal
digits. The hexadecimal letters (A–F or
a–f) are case-insensitive.
How to Use Hexadecimal References
- Find the hexadecimal code point for the target character (omitting
the
U+prefix). - Place the hex value between

nd;.
Examples
Copyright Symbol (
©): Unicode code point isU+00A9.<notice>Copyright © 2024</notice>Ampersand (
&): Unicode code point isU+0026.<company>Smith & Sons</company>Euro Sign (
€): Unicode code point isU+20AC.<price>€50.00</price>
Comparison: Decimal vs. Hexadecimal
Both decimal and hexadecimal forms achieve identical results during XML parsing. The choice between them comes down to context and convention:
| Character | Name | Decimal Form | Hexadecimal Form |
|---|---|---|---|
< |
Less-than sign | < |
< |
> |
Greater-than sign | > |
> |
" |
Quotation mark | " |
" |
♥ |
Black Heart Suit | ♥ |
♥ |
ñ |
Latin Small Letter N with Tilde | ñ |
ñ |
While decimal forms use only standard numerals 0-9,
hexadecimal forms require the x flag and can utilize digits
0-9 along with letters A-F.