Using Numeric Character References

This section describes how numeric character references can be used in HTML documents. Numeric character references allow you to represent any Unicode code points in HTML documents.

HTML5 also supports numeric character references to represent any Unicode code points. You need to remember the following notes when using them:

1. A numeric character reference can be written in decimal format as "&#nnnn;", where nnnn is the code point in decimal digits. For example, "&60;" is a numeric character reference to Unicode code point of U+0003C for character "<".

2. A numeric character reference can be written in hexadecimal format as "&#xhhhh;", where hhhh is the code point in hexadecimal digits. For example, "&x3c;" is a numeric character reference to Unicode code point of U+0003C for character "<".

3. Numeric character references can be used in element contents of all HTML elements except "script" and "style" elements.

6. Numeric character references in "svg" and "math" element contents must follow XML rules.

7. Numeric character references can also be used in attribute values.

Here is example HTML document that shows you how to use character entity references:

<!DOCTYPE html>
<!-- HTM_Numeric_Character_References_Example.html
 - Copyright (c) 2009 HerongYang.com. All Rights Reserved.
-->
<html>
<head>
<!-- Numeric Character References in "title" element -->
<title>&#34;Character Entity References&#x22; Example</title>
</head>
<body>

<!-- Numeric Character References in element content -->
<pre>
U+0003C &#34; &#x22; &#034; &#x0022;
U+000A9 &#169; &#xA9;
</pre>

<!-- Numeric Character References in attribute value -->
<img src="image.gif" alt="In attribute value: &#xA9;">

<!-- Bad examples -->
<script>U+000A9 &#169; &#xA9;</script>

</body>
</html>

When the above HTML document is viewed in a Web browser, you will see something like this:

HTML5 Numeric Character Reference Example
HTML5 Numeric Character Reference Example

Table of Contents

 About This Book

 Introduction of HTML

 Introduction of HTML5 Features

 HTML Document Structure and Content

HTML Document and Elements Syntax

 HTML Document Syntax

 Document Character Set and Encoding

 Entering Comments in HTML Document

 Opening and Closing Tags of Elements

 Using Nested Elements

 Specifying Element Attributes

 Specifying Element Contents

 Element Content Syntax Types

 Using Whitespace Characters

 Using Character Entity References

Using Numeric Character References

 Displayed and Printed HTML Documents

 Responsive Design of Web Pages

 MathML Integration in HTML Documents

 References

 Full Version in PDF/EPUB