Lesson 12: Character Entity References
Master the use of HTML entities to display special characters and symbols on your web pages
Start LearningUnderstanding Character Entities
HTML provides character entity references to display special characters that are reserved for use in HTML or that don't appear on standard keyboards. These entities ensure your content displays correctly across all browsers and devices.
Why Use Character Entities?
HTML reserves certain characters for its syntax. For example:
- The less-than sign (<) is used to start HTML tags
- The ampersand (&) is used to start entity references
- Quotation marks (") are used for attribute values
To display these characters as content, you must use their corresponding HTML entities.
Essential Character Entities
Here are the most commonly used character entities in HTML:
Character | Entity Name | Entity Number | Description | Usage |
---|---|---|---|---|
< | < |
< |
Less than | Prevent HTML tag interpretation |
> | > |
> |
Greater than | Prevent HTML tag interpretation |
& | & |
& |
Ampersand | Prevent entity interpretation |
" | " |
" |
Double quotation mark | Inside attribute values |
' | ' |
' |
Single quotation mark | Inside attribute values |
|
  |
Non-breaking space | Prevent line breaks between words | |
© | © |
© |
Copyright symbol | Copyright notices |
® | ® |
® |
Registered trademark | Trademark notices |
€ | € |
€ |
Euro currency | Financial content |
Using Entities in Practice
Let's see how to use character entities in real HTML code:
Basic Entity Usage
<p>To display HTML tags, use entities: <div>Content</div></p> <p>Copyright © 2023 My Company. All rights reserved.</p> <p>The price is 100€ + 20% VAT.</p> <p>Special characters: ♥ ♦ ♣ ♠</p> <p>Mathematical operators: ∑ ∏ √ ∞</p>
Result:
To display HTML tags, use entities: <div>Content</div>
Copyright © 2023 My Company. All rights reserved.
The price is 100€ + 20% VAT.
Special characters: ♥ ♦ ♣ ♠
Mathematical operators: ∑ ∏ √ ∞
Advanced Entity Usage
<!-- Displaying code examples --> <pre> function calculate(a, b) { return a < b ? a : b; } </pre> <!-- Using entities in attributes --> <input type="text" placeholder="Search …"> <!-- Creating non-breaking spaces --> <p>Dr. Liew Voon Kiong</p> <!-- Currency symbols --> <p>Price: $49.99 | £39.99 | ¥5499</p>
Result:
function calculate(a, b) { return a < b ? a : b; }
Dr. Liew Voon Kiong
Price: $49.99 | £39.99 | ¥5499
Special Characters & Symbols
HTML provides entities for thousands of special characters. Here are some useful categories:
Common Symbols
Mathematical Symbols
Arrows & Shapes
Practical Exercise: Using Entities
Create a webpage section using HTML entities with the following requirements:
Your Task:
- Create a copyright notice: © 2023 Your Company Name
- Display a mathematical equation: 5 × 3 < 20 ÷ 2
- Show currency values: $49.99, €44.99, ¥5499
- Include a registered trademark: HTML Tutor®
- Create a navigation indicator: Home → Products → Details
- Add a decorative element: I ♥ HTML!
Tips:
- Use
©
for the copyright symbol - Use
×
for multiplication and÷
for division - Remember to encode less-than signs:
<
- Use
®
for the registered trademark - Use arrow entities:
→
- Use
♥
for the heart symbol