HTML Entities: A Complete Guide to Character Encoding
When you write HTML content, you occasionally need to display characters that have special meaning in HTML markup itself. A less-than sign < looks like the start of a tag. An ampersand & could be the beginning of an entity. A quotation mark " might close an attribute. HTML entities solve this problem by providing a standardized way to represent any character — from reserved symbols to emoji to mathematical operators — using safe text sequences. This guide explains what entities are, why they matter, and how to use them correctly.
What are HTML Entities?
HTML entities are a mechanism for representing characters in HTML documents using a special syntax. Instead of writing a character directly, you write a code that the browser interprets and renders as that character.
There are three ways to write an HTML entity:
Named Entities
Named entities use a descriptive name surrounded by ampersand and semicolon:
&name;
For example:
&renders as&<renders as<"renders as" renders as a non-breaking space
Named entities are human-readable and widely supported. Use them whenever a named entity exists for your character.
Decimal Numeric Entities
Decimal entities use the character’s Unicode code point as a decimal number:
&#number;
For example:
&renders as&(code point 38)<renders as<(code point 60)©renders as©(code point 169)😀renders as 😀 (code point 128512)
Hexadecimal Numeric Entities
Hex entities are similar to decimal but use hexadecimal notation with an x prefix:
&#xhex;
For example:
&renders as&(hex: 0x26)<renders as<(hex: 0x3C)©renders as©(hex: 0xA9)😀renders as 😀 (hex: 0x1F600)
The three forms are completely equivalent — the browser renders them identically. Choose the form that makes sense for your use case.
Why Use HTML Entities?
HTML entities solve several practical problems:
Reserved Characters in HTML Markup
Certain characters have structural meaning in HTML and cannot be written literally in content without confusing the parser:
<and>delimit tags&starts entity references"and'delimit attribute values
For example, if you want to display a code example like if (x < 5), you must encode the < as < or <:
<!-- Wrong — the < breaks the HTML: -->
<p>In JavaScript: if (x < 5) then...</p>
<!-- Correct — reserved characters encoded: -->
<p>In JavaScript: if (x < 5) then...</p>
Without encoding, the browser’s HTML parser may truncate content, misinterpret tags, or produce a broken document.
Representing Characters Not on Your Keyboard
Many useful characters — mathematical symbols, arrows, currency signs, accented letters — are difficult or impossible to type directly. Entities provide a reliable, portable way to include them:
<!-- Instead of trying to type special characters: -->
<p>Price: £99.99</p>
<p>Copyright © 2026</p>
<p>x × y = z</p>
<p>Direction: →</p>
Character Encoding Compatibility
In legacy systems or contexts where UTF-8 encoding cannot be guaranteed, numeric entities ensure that all characters render correctly regardless of the underlying character encoding scheme. Modern web development uses UTF-8 almost universally, but entities provide a compatibility fallback.
Cross-Browser and Device Compatibility
Named entities are standardized across all browsers. Numeric entities using Unicode code points work everywhere. This makes entities a portable, future-proof way to include special characters.
Essential HTML Entities
These entities are used in most HTML documents and should be memorized:
| Character | Named Entity | Decimal | Hexadecimal | Use Case |
|---|---|---|---|---|
& | & | & | & | Reserved character; always encode in text and attributes |
< | < | < | < | Opening bracket; encode in text content |
> | > | > | > | Closing bracket; encode after ]]> |
" | " | " | " | Double quote in double-quoted attributes |
' | ' | ' | ' | Apostrophe/single quote in single-quoted attributes |
| Space (non-breaking) | |   |   | Prevent line breaks; preserves multiple spaces |
| © | © | © | © | Copyright symbol |
| ™ | ™ | ™ | ™ | Trademark symbol |
| € | € | € | € | Euro currency |
| £ | £ | £ | £ | British pound |
| ¥ | ¥ | ¥ | ¥ | Yen/yuan currency |
| × | × | × | × | Multiplication sign |
| ÷ | ÷ | ÷ | ÷ | Division sign |
| ± | ± | ± | ± | Plus-or-minus sign |
| ≈ | ≈ | ≈ | ≈ | Approximately equal |
| → | → | → | → | Right arrow |
| ← | ← | ← | ← | Left arrow |
| ↑ | ↑ | ↑ | ↑ | Up arrow |
| ↓ | ↓ | ↓ | ↓ | Down arrow |
| ✓ | ✓ | ✓ | ✓ | Check mark |
| ✕ | ✗ | ✕ | ✗ | Cross/X mark |
| … | … | … | … | Ellipsis (three dots) |
| — | — | — | — | Em dash |
| – | – | – | – | En dash |
Numeric vs Named Entities
Both numeric and named entities are valid HTML. When should you use each?
Use Named Entities When:
- A standard named entity exists for your character (most common ones do)
- Readability matters —
©is more meaningful than© - You’re encoding reserved characters:
&,<,>,",'
Example:
<footer>
<p>© 2026 Acme Corp. All rights reserved.</p>
<p>Terms & Conditions | Privacy Policy</p>
<p>Email us at: contact@example.com — we’d love to hear from you.</p>
</footer>
Use Numeric Entities When:
- No named entity exists (especially for rare or very new Unicode characters)
- Encoding from a script or automatic process
- Maximum compatibility is required
Example:
<!-- Unicode emoji and symbols without standard names -->
<p>Feedback: 😀 😊 😎 😎 🎉 🎉</p>
<!-- Mathematical operators -->
<p>x ∴ y (therefore)</p>
<p>A ⊂ B (subset of)</p>
Best Practice
Use named entities for common characters (reserved symbols, currency, arrows, punctuation). Use numeric entities for everything else (emoji, obscure symbols, mathematical operators). Most modern web pages use UTF-8 encoding, so you can also type characters directly as UTF-8:
<!-- All three approaches work in modern HTML with UTF-8: -->
<p>Copyright © 2026</p>
<p>Copyright © 2026</p>
<p>Copyright © 2026</p>
Choose whichever feels most maintainable for your team.
Common Use Cases
Displaying Code and Programming Examples
When writing tutorials or documentation that display code, you must encode the angle brackets and ampersands:
<p>In HTML, tags are written like <code><div></code> or <code><p></code>.</p>
<p>To concatenate strings in JavaScript: <code>str1 + str2</code> or <code>str1.concat(str2)</code>.</p>
<p>In SQL, logical AND is <code>&&</code>, and logical OR is <code>||</code>.</p>
<!-- For larger code blocks, use <pre> with encoding: -->
<pre><!DOCTYPE html>
<html>
<head>
<title>Hello World</title>
</head>
<body>
<h1>Welcome</h1>
</body>
</html></pre>
Copyright, Trademark, and Legal Symbols
<footer>
<p>© 2026 Acme Corporation®. All rights reserved.</p>
<p>Acme™ is a registered trademark of Acme Corp.</p>
<p>Licensed under the MIT License — see LICENSE file for details.</p>
</footer>
Mathematical and Scientific Notation
<p>The formula for kinetic energy is: E = ½mv²</p>
<p>Pythagorean theorem: a² + b² = c²</p>
<p>Infinity symbol: ∞</p>
<p>Partial derivative: ∂f/∂x</p>
<p>For all: ∀x ∈ ℝ, x² ≥ 0</p>
Navigation and UI Arrows
<nav>
<a href="/previous">← Previous</a>
<a href="/next">Next →</a>
<a href="/up">↑ Back to Top</a>
</nav>
<p>Click the menu icon ≡ to expand navigation.</p>
Quotation Marks and Dashes
<blockquote>
<p>“The best way to predict the future is to invent it.”</p>
<p>— Alan Kay</p>
</blockquote>
<p>En dash (date ranges): January – March 2026</p>
<p>Em dash (thought break): Let’s go — or maybe not.</p>
Accented Characters and International Text
<!-- While modern UTF-8 allows direct typing, entities ensure compatibility: -->
<p>Café — a place to relax</p>
<p>Naïve approach vs. sophisticated method</p>
<p>Österreich (Austria) and Öl (oil) use the same character.</p>
HTML Entities vs URL Encoding
HTML entities and URL encoding are often confused because they both use escape sequences. They serve entirely different purposes and apply in different contexts:
| Aspect | HTML Entities | URL Encoding |
|---|---|---|
| Where applied | Inside HTML document content and attributes | Inside URLs (scheme, path, query, fragment) |
| Syntax | &name;, &#number;, &#xhex; | %XX (hex bytes) |
| Example | <, &, | %3C, %26, %20 |
| When needed | Reserved HTML characters (<, >, &, ", ') and special symbols | Reserved URL characters (/, ?, #, &, =, etc.) and non-ASCII characters |
Practical distinction:
<!-- HTML content uses entities: -->
<p>Visit our site at <a href="https://example.com/search?q=C%2B%2B">our search page</a>.</p>
<!-- The text of the link would be: -->
Search for C++ & Java
<!-- If you need an ampersand in an HTML attribute, use an entity: -->
<a href="https://example.com/search?q=cats&dogs">Search</a>
<!-- Do NOT double-encode: -->
<!-- Wrong: -->
<a href="https://example.com/search?q=cats%26dogs">Search</a>
<!-- Correct: -->
<a href="https://example.com/search?q=cats%26dogs">Search</a>
The rule is simple: use HTML entities for content and attributes within HTML, and URL encoding for URLs themselves. Never mix the two.
UTF-8 and the Future of Entities
HTML originally supported entities because character encodings were fragmented. With the dominance of UTF-8 (a universal encoding that represents all Unicode characters), you can now type most characters directly in your HTML source code:
<!-- Modern approach (UTF-8): -->
<p>Copyright © 2026</p>
<p>Price: €99.99</p>
<p>Café near the Straße</p>
<p>Emoji: 🎉 🚀 ✨</p>
This works perfectly as long as:
- Your HTML file is saved as UTF-8
- The
<meta charset="utf-8">tag is present in the document head - Your server sends the correct
Content-Type: text/html; charset=utf-8header
When entities are still necessary:
- Reserved HTML characters (
&,<,>,",') must always be encoded - Character encoding fallbacks in legacy systems
- Clarity and semantic meaning (e.g.,
©is more readable than©) - Situations where you must match specific stylistic or content management requirements
Modern best practice is to use UTF-8 for all characters you can type, use HTML entities only for reserved characters and rare symbols, and rely on named entities where they provide semantic clarity.
Quick Reference Table
Here are 30 of the most useful HTML entities:
| Character | Named Entity | Decimal | Use |
|---|---|---|---|
& | & | & | Text data and attributes |
< | < | < | Code examples and markup |
> | > | > | Code examples and markup |
" | " | " | Double-quoted attributes |
' | ' | ' | Single-quoted attributes |
(non-breaking) | |   | Fixed spacing |
| © | © | © | Copyright notices |
| ® | ® | ® | Registration symbol |
| ™ | ™ | ™ | Trademark symbol |
| € | € | € | Euro currency |
| £ | £ | £ | Pound sterling |
| ¥ | ¥ | ¥ | Yen/yuan |
| ¢ | ¢ | ¢ | Cent symbol |
| × | × | × | Multiplication |
| ÷ | ÷ | ÷ | Division |
| ± | ± | ± | Plus-or-minus |
| ≈ | ≈ | ≈ | Approximately equal |
| ≠ | ≠ | ≠ | Not equal |
| ≤ | ≤ | ≤ | Less than or equal |
| ≥ | ≥ | ≥ | Greater than or equal |
| → | → | → | Right arrow |
| ← | ← | ← | Left arrow |
| ↑ | ↑ | ↑ | Up arrow |
| ↓ | ↓ | ↓ | Down arrow |
| ✓ | ✓ | ✓ | Checkmark |
| — | — | — | Em dash |
| – | – | – | En dash |
| … | … | … | Ellipsis |
| ” | “ | “ | Left double quote |
| ” | ” | ” | Right double quote |
For a complete, searchable reference of all named entities, use our HTML Entity Encoder tool.
FAQ
Should I use entities or UTF-8 directly?
If you can type the character directly (and your editor supports UTF-8), do so. Use entities only for reserved characters (&, <, >, ", '), obscure symbols without convenient keyboard input, or for semantic clarity. Modern browsers and systems universally support UTF-8.
Why does my entity not render correctly?
Common causes: (1) Missing semicolon at the end (© instead of ©), (2) Misspelled entity name (©write; instead of ©), (3) Invalid numeric value, or (4) Character encoding mismatch. Ensure your HTML file is saved as UTF-8 and includes <meta charset="utf-8">.
Can I use entities in JavaScript strings?
Entities are HTML syntax, not JavaScript syntax. In JavaScript, use Unicode escape sequences instead: "\u00A9" for ©, "\u2122" for ™. However, if JavaScript outputs HTML, encode entities as part of the HTML generation.
Are entity references cached or optimized?
Modern browsers parse and render entities instantly. There is no performance penalty for using entities compared to UTF-8 characters. Choose based on readability and maintainability, not performance.
What if a named entity doesn’t exist?
Use the numeric form. Every Unicode character has a code point, so you can always use &#number; or &#xhex; as a fallback. However, the browser must support rendering that character (which requires an appropriate font), so some rare or very new Unicode characters may not display if the user’s system lacks the font.
Further Reading
- URL Encoding Explained: Why and How It Works — the companion encoding system for URLs vs HTML
- What is Base64 Encoding? — another encoding scheme developers encounter daily
- Base64 Encoding in JavaScript, Python & Go — practical code for the most common encoding tasks
Conclusion
HTML entities are a foundational part of HTML syntax. While modern UTF-8 encoding has reduced the need for entities, they remain essential for encoding reserved characters and providing semantic clarity in markup. Master the essential entities (&, <, >, ", ', ), use named entities for common symbols, and rely on numeric entities for everything else.
Need to encode characters quickly? Use our HTML Entity Encoder tool to convert text to entities instantly. It supports batch conversion, provides both named and numeric forms, and handles reserved characters automatically.