HTML Character Entities | Novice Tutorial
Novice Tutorial -- Learning is not just about technology, but also dreams!
- Home
- HTML
- JavaScript
- CSS
- Vue
- React
- Python3
- Java
- C
- C++
- C#
- AI
- Go
- SQL
- Linux
- VS Code
- Bootstrap
- Git
- Local Bookmarks
HTML Tutorial
HTML Tutorial HTML Introduction HTML Editors HTML Basics HTML Elements HTML Attributes HTML Headings HTML Paragraphs HTML Text Formatting HTML Links HTML Head HTML CSS HTML Images HTML Tables HTML Lists HTML Blocks HTML Layouts HTML Forms HTML Iframes HTML Colors HTML Color Names HTML Color Values HTML Scripts HTML Character Entities HTML URL HTML Quick List HTML Tag Abbreviations and Full Names HTML Summary HTML Quiz XHTML Introduction
HTML5
HTML5 Tutorial HTML5 Browser Support HTML5 New Elements HTML5 Canvas HTML5 SVG HTML5 MathML HTML5 Drag and Drop HTML5 Geolocation HTML5 Video HTML5 Audio HTML5 Input Types HTML5 Form Elements HTML5 Form Attributes HTML5 Semantic Elements HTML5 Web Storage HTML5 Web SQL HTML5 Web IndexedDB HTML5 Application Cache HTML5 Web Workers HTML5 SSE HTML5 WebSocket
HTML Character Entities
In HTML, some characters are reserved. For example, the less-than sign (<) and greater-than sign (>) are used to define HTML tags. If you want to display these reserved characters correctly, you must use character entities in the HTML source code.
Character entities are referenced in three ways:
- Entity name: &entity_name; (e.g., < displays <)
- Entity number (decimal): &#number; (e.g., < displays <)
- Entity number (hexadecimal): &#xnumber; (e.g., < displays <)
Note: Although entity names are easier to remember, not all browsers support the latest entity names. Entity numbers, on the other hand, are more widely supported.
Commonly Used HTML Character Entities
| Display Result | Description | Entity Name | Entity Number |
|---|---|---|---|
| < | less-than | < | < |
| > | greater-than | > | > |
| & | ampersand | & | & |
| " | double quotation mark | " | " |
| ' | single quotation mark (apostrophe) | ' | ' |
| ¢ | cent | ¢ | ¢ |
| £ | pound | £ | £ |
| ¥ | yen | ¥ | ¥ |
| € | euro | € | € |
| © | copyright | © | © |
| ® | registered trademark | ® | ® |
| non-breaking space | |   |
More complete entity references can be found in the HTML Entity Reference Manual.
Non-breaking Space (nbsp)
A non-breaking space ( ) is a space that will not break into a new line. Two words separated by a non-breaking space will stay together on the same line. This is useful when you do not want a line break to occur (e.g., between a number and its unit).
Example: 10 km/h
Using Character Entities in HTML
To display a less-than sign in a paragraph, use the following code:
<p>The less-than sign: < </p>
The above code will display: The less-than sign: <
Important Note
When writing HTML, always use character entities for the following characters to avoid parsing errors: <, >, &, ", and '. In attribute values, double quotes should be escaped as " and single quotes as '.
Example of escaping attribute:
<a href="#" title="He said "Hello"">Link</a>
Browser Compatibility
All modern browsers support character entities. However, entity names introduced in newer versions of HTML may not be recognized by older browsers. For maximum compatibility, use decimal or hexadecimal entity numbers.
```
YouTip