Using Character Entity References

This section describes how character entity references can be used in HTML documents. HTML5 supports about 2231 predefined character entity reference names. Most of them are case sensitive and end with ';'.

HTML5 supports a predefined set of character entity reference names that are mapped to a set of Unicode code points. You need to remember the following notes when using them:

1. There are about 2231 character entity reference names defined in HTML5. Check the HTML5 specification document at http://www.w3.org/TR/html5/syntax.html to get the complete list of character entity reference names.

2. Most reference names end with ";". But for some commonly used characters, two versions are support: one with ";" and one without ";". For example, both "lt;" and "lt" are supported referring to the same code point of U+0003C. It is strongly recommended to use the reference name with ";".

3. Most reference names are case sensitive. But for some commonly used characters, two versions are support: one with upper case and one with lower case. For example, both "LT;" and "lt" are supported referring to the same code point of U+0003C. It is strongly recommended to use the lower case reference name.

4. You enter character entity references to refer to their mapped Unicode code points in a HTML document using this syntax: "&reference_name;". "<" is entity reference to code point of U+0003C.

5. Character entity references can be used in element contents of all HTML elements except "script" and "style" elements.

6. Character entity references in "svg" and "math" element contents must follow XML rules.

7. Character entity 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_Character_Entity_References_Example.html
 - Copyright (c) 2014, HerongYang.com, All Rights Reserved.
-->
<html>
<head>
<!-- Character Entity References in "title" element -->
<title>"Character Entity References&quot; Example</title>
</head>
<body>

<!-- Character Entity References in element content -->
<pre>
U+0003C &lt;
U+0003C &LT;
U+0003C &lt
U+0005B &lsqb;
U+0226A &Lt;
</pre>

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

<!-- Bad examples -->
<script>U+0003C &lt;</script>
<pre>
&lsqb   "lsqb;" is defined, not "lsqb"
&LSGB;  "lsqb;" is defined, not "LSGB"
&lT;    "Lt;" is defined, not "lT;"
</pre>

</body>
</html>

When the above HTML document is viewed in a Web browser, you will see something like this:
HTML5 Character Entity Reference Example

Last update: 2014.

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

 References

 PDF Printing Version