Some characters have special meaning in HTML (like <, >, and &).
To display them literally, use HTML entities. An entity can be written as a
named entity (e.g., &) or a numeric reference (e.g., & or &).
HTML Entities
1) Why Entities?
<!-- If you want to show <div> in the browser, you must escape it -->
<div>Hello</div>
Rendered output: <div>Hello</div>
Common HTML Entities
| Character | Named | Decimal | Hex | Description |
|---|---|---|---|---|
| & | & | & | & | Ampersand |
| < | < | < | < | Less-than |
| > | > | > | > | Greater-than |
| " | " | " | " | Double quote |
| ' | ' | ' | ' | Single quote / apostrophe |
|   |   | Non-breaking space | |
| © | © | © | © | Copyright |
| ® | ® | ® | ® | Registered trademark |
| ™ | ™ | ™ | ™ | Trademark |
| € | € | € | € | Euro sign |
| ₹ | ₹ | ₹ | ₹ | Indian Rupee (no named entity) |
| — | — | — | — | Em dash |
| – | – | – | – | En dash |
| ← | ← | ← | ← | Left arrow |
| → | → | → | → | Right arrow |
| ✓ | ✓ | ✓ | ✓ | Check mark |
2) Non-breaking Space ( )
<!-- Prevent automatic line breaks between words -->
C With Sonu
Rendered: C With Sonu (stays on one line)
3) Quotes Inside Attributes
<div title="He said "Hello"">Hover me</div>
Hover me
4) Numeric References (Decimal / Hex)
<!-- Decimal -->
© <!-- © -->
<!-- Hexadecimal -->
₹ <!-- ₹ -->
Rendered: © ₹
5) Showing Code Literally
<h1>Codingwithsonu</h1>
Rendered: <h1>Codingwithsonu</h1>
Tips:
- Prefer UTF-8 (already set via
<meta charset="utf-8">). Use entities only when needed. - Use entities in HTML text and attribute values when the character would otherwise break markup.
- Both named and numeric references are valid. Numeric is universal even when a named variant doesn’t exist.