HTML Entities: Syntax Encoding, Reserved Characters & Security Mechanics
An HTML Entity (character reference) is an escape sequence used to represent characters that either cannot be keyed directly on standard keyboards, would otherwise be misinterpreted as markup syntax, or require precise typographical line-breaking control.
1. Anatomy & Formats of Character References
1. Named Entity Reference
&entity_name;Starts with an ampersand (&) and ends with a semicolon (;). Example: © produces ©. Case-sensitive!
2. Decimal Numeric Reference
&#decimal_number;Begins with &# followed by the base-10 Unicode code point. Example: © produces ©.
3. Hexadecimal Numeric Reference
&#xhex_code;Begins with &#x followed by the base-16 hex code point. Example: © produces ©. Universally compatible with XML.
2. The 5 Essential Reserved HTML Characters
These 5 characters hold syntactical meaning in HTML and must always be escaped in dynamic output to prevent parser corruption and Cross-Site Scripting (XSS):
| Character | Name / Role | Named Entity | Decimal Code | Hexadecimal Code | Syntax Danger |
|---|---|---|---|---|---|
< | Less-than | < | < | < | Starts an HTML tag; unescaped creates rogue DOM elements. |
> | Greater-than | > | > | > | Closes an HTML tag; breaks tag attributes. |
& | Ampersand | & | & | & | Starts an entity reference; unescaped corrupts query strings. |
" | Double Quote | " | " | " | Delimits attributes; premature closing causes attribute injection. |
' | Single Quote | ' | ' | ' | Delimits single-quoted attributes and inline JavaScript strings. |
3. Professional Typographic & Currency Reference Table
| Symbol | Name & Meaning | Named Entity | Unicode Code Point | Typographic Usage |
|---|---|---|---|---|
| Non-Breaking Space | | U+00A0 ( ) | Glues two words together, preventing lonely orphan line breaks. | |
| — | Em-dash | — | U+2014 (—) | Indicates a thematic pause or parenthetical thought in prose. |
| – | En-dash | – | U+2013 (–) | Represents numerical or date ranges (e.g., 2020–2026). |
| … | Horizontal Ellipsis | … | U+2026 (…) | Typographic three-dot omission (better than typing three periods). |
| “ ” | Curly Quotes (Double) | “ / ” | U+201C / U+201D | Professional typographic smart quotes for literature and editorial. |
| € | Euro Currency | € | U+20AC (€) | European Union currency symbol. |
| £ | British Pound | £ | U+00A3 (£) | United Kingdom currency symbol. |
| ¥ | Japanese Yen / Yuan | ¥ | U+00A5 (¥) | Japanese and Chinese monetary symbol. |
| ₹ | Indian Rupee | ₹ | U+20B9 (₹) | Official Indian national currency symbol. |
| © | Copyright Symbol | © | U+00A9 (©) | Legal copyright notice in website footers. |
| ® | Registered Trademark | ® | U+00AE (®) | Federally registered commercial trademark indicator. |
| ™ | Unregistered Trademark | ™ | U+2122 (™) | Unregistered product trademark sign. |
4. Security Deep Dive: XSS Sanitization via Entity Escaping
Cross-Site Scripting (XSS) consistently ranks among the OWASP Top 10 web vulnerabilities. When rendering user comments or search strings into HTML templates:
// Vulnerable Node.js / Express code (DO NOT DO THIS):
res.send(`<h1>Search Results for: ${req.query.q}</h1>`);
// Attacker searches: <script>fetch('/steal?cookie='+document.cookie)</script>
// Browser executes the script immediately!
// Secure Code using Entity Sanitization:
function escapeHtml(str) {
return str
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''');
}
res.send(`<h1>Search Results for: ${escapeHtml(req.query.q)}</h1>`);
// Output sent to browser:
// <script>fetch(...)</script>
// The browser safely displays the raw text without executing it!