HTML Character Entities Reference
HTML character entities are special codes used to display characters that have special meaning in HTML or characters that are not easily typed on a keyboard. They begin with an ampersand (&) and end with a semicolon (;).
Why Use HTML Entities?
- Reserved Characters: HTML uses certain characters like <, >, and & for markup. To display these literally, you must use entities.
- Special Characters: Display characters not available on standard keyboards like ©, ®, or mathematical symbols.
- Unicode Support: Ensure proper display of international characters across different systems and browsers.
- Accessibility: Screen readers can properly interpret entity names for better accessibility.
Entity Formats
Named Entities: ©
→ ©
Decimal Entities: ©
→ ©
Hexadecimal Entities: ©
→ ©
Common Categories
Basic HTML
Essential characters like <, >, & that are reserved in HTML.
Punctuation
Quotation marks, dashes, and other punctuation symbols.
Mathematical
Mathematical operators, symbols, and notation.
Currency
Currency symbols from around the world.
Symbols
Copyright, trademark, and other common symbols.
International
Latin and Greek characters with diacritical marks.
Best Practices
- Use Named Entities: When available, named entities are more readable than numeric ones.
- Always Use Entities for Reserved Characters: Never use raw <, >, or & in HTML content.
- Consider UTF-8: With proper UTF-8 encoding, many special characters can be used directly.
- Validate Your Code: Ensure all entities are properly formed and recognized.
- Browser Compatibility: Test entities across different browsers, especially older ones.
Development Examples
HTML Example:
<p>Copyright © 2024 — All rights reserved</p> <p>Price: £19.99 (includes 20% VAT)</p> <p>“Hello, world!” she said.</p>
JavaScript/React Example:
// Using dangerouslySetInnerHTML <div dangerouslySetInnerHTML={{__html: 'Price: £19.99'}} /> // Using Unicode in JavaScript strings const copyright = '\u00A9 2024'; const quote = '\u201CHello, world!\u201D';
Common Mistakes
- Forgetting the Semicolon:
©
without semicolon may not render correctly. - Case Sensitivity: Named entities are case-sensitive:
&Copy;
≠©
- Invalid Entities: Using non-existent entity names will display literally.
- Double Encoding: Encoding already-encoded entities can cause display issues.
💡 Pro Tip
Use this reference tool to quickly find the correct entity for any special character. Copy the entity code and paste it directly into your HTML, or use the Unicode value in your JavaScript strings for consistent cross-platform display.