HTML Entities Reference
HTML entities let you display reserved and special characters. This table covers the most common named entities with their decimal/hex numeric forms and descriptions.
How It Works
HTML entities encode characters that would break parsing or cannot be typed. Three must always be escaped: <, > and &, otherwise the browser treats them as tags or entity boundaries.
Entities come as named (©, ) or numeric (©, • hex). They both prevent XSS (turn a user's < into <) and render symbols like copyright or arrows. But entities do not defeat whitespace collapsing — consecutive spaces are still merged by HTML.
When to Use This Table
This table is for writing special characters safely into HTML or recovering the original characters from HTML. It gives the named entity (&), the decimal and hexadecimal numeric forms, and the purpose of each character. Generators, parsers, escaping and unescaping all depend on it.
When not to consult it: you are doing full HTML sanitisation or XSS defence. This table only explains what the characters are, not which ones to escape and when — that is a sanitiser library such as DOMPurify, and treating the entity table as a security checklist misses a great deal of attack surface.
Rule of thumb: judge by the role the character plays in the output position. In text nodes < > & " and need escaping; in attribute values it also depends on the quote style, since a single quote need not be escaped inside double quotes and vice versa; in URL parameters & and = are delimiters and must be encoded.
Mind the semicolon: HTML allows omitting the trailing semicolon (& parses as &), but inside a text node followed by a letter it becomes ambiguous (&x parses as &x). Always write the full semicolon for the best compatibility.
Boundaries and Common Pitfalls
Semicolons are optional and get silently reinterpreted when a letter follows
HTML5 lets & without a semicolon parse as &. But if a letter or digit follows, the parser tries the longest match: in some parsers &x becomes &x (the x is absorbed into the entity name) rather than the literal &x. That is silent content loss triggered only in specific contexts, which makes it extremely hard to debug. The rule is simple: always emit the full &.
Entity encoding is not XSS defence — the browser decodes before parsing
Writing < as < only helps inside a text node. Put the same input into an attribute, a URL or a script context and the browser may decode entities at an earlier stage, defeating the protection: <img src=x onerror=alert(1)> placed in an unquoted attribute with angle brackets entity-encoded can still yield an executable event handler. The real fix is context-aware encoding (HTML text, attribute, JS string and URL each have their own rules) or DOMPurify for anything high risk.
Double encoding leaves an extra layer of literal text
Encoding already-encoded text again turns & into &amp; and the page shows a literal & instead of &. The usual trigger is double serialisation: the template engine auto-escapes and the code escapes again, or JSON embedded in HTML is passed through an encoding layer. Debug by inspecting the actual DOM text rather than the source, where multiple layers of & are often normal.
How This Relates to Neighbours
To see what a character looks like and its code point, use the in-site ASCII and character-encoding pages; this one covers the HTML entity layer.
Percent-encoding in URLs (%20, %E4%B8%AD) belongs to the URL encoding page — it is a different mechanism from HTML entities.
To escape or unescape text in bulk, use the in-site HTML tools; this table is a semantic reference, not a processing pipeline.
If the goal is XSS defence, this table is not a sufficient basis — use a mature sanitiser together with CSP rather than hand-picking characters to escape.
Practical Snippet
Key points: (1) never omit the semicolon — when a letter follows, HTML5 longest-match absorbs it into the entity name and content is silently lost; (2) entity encoding only protects text nodes; attributes and script contexts need context-aware encoding or DOM-based construction, and anything high risk deserves DOMPurify plus CSP; (3) always quote attribute values, since an unquoted attribute breaks on the first space; (4) to unescape, use textarea or DOM parsing instead of hand-written regular expressions, which easily miss nested entities.
// ① Three equivalent forms (always include the semicolon)
const s = '&' // & the character itself
'&' // & named entity
'&' // & decimal
'&' // & hexadecimal
// ② Build with the DOM instead of string concatenation (auto-escaped, safest default)
const el = document.createElement('div')
el.textContent = '<script>alert(1)</script>' // Plain text, never parsed as markup
el.innerHTML = '<script>alert(1)</script>' // ⚠️ Parsed into a real element; on* handlers run, so never feed user input here
document.body.append(el)
// ③ When you must build HTML, escaping the 5 text-node characters is enough
const ESC = { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }
const esc = s => String(s).replace(/[&<>"']/g, c => ESC[c])
// ④ Attributes: which quote to escape depends on the quoting style
const attrDouble = 'data-x="' + esc(userInput) + '"' // Double-quoted ⇒ single quotes need no extra escaping
// ⚠️ Unquoted attributes are the riskiest: a space escapes them, so always quote
// <div class=USER> ← breaks as soon as USER contains a space
// ⑤ Unescaping: prefer the DOM over your own regex
const decode = html => {
const d = document.createElement('textarea')
d.innerHTML = html
return d.value
}
console.log(decode('<b>')) // <b> (as text, not a tag)
// ⑥ Watch for entities written without a semicolon
const risky = '&x' // Some parsers read it as &x and eat the rest
console.log(risky) // Always write '&x' insteadPractical Notes
- Named entities end with a semicolon; omitting it makes the parser guessWhen the semicolon is missing the HTML parser falls back to the longest known entity: & still renders as &, but ¬in becomes ¬ followed by "in". This is especially error-prone for & followed by letters inside attribute values, so always write the semicolon.
- is a no-break space, not a regular spaceIts code point is U+00A0. Regexes that replace ordinary spaces (for example turning spaces into underscores) will silently skip it, while using it for layout prevents text from wrapping on narrow screens. Normalize U+00A0 to U+0020 during data cleanup.
- Do not use entities inside <script> or preformatted blocks<script> is a raw-text element: its content is not entity-decoded, so writing & puts the literal text & into the JS string instead of &. In <pre>/<textarea> decoding does happen but rewrites the original input, so output already-escaped text instead.
Data Sources
- WHATWG HTML Standard §13.5 (named character references)
Codes, names and definitions above come from public specifications; we claim no originality over the specification data itself. The arrangement, Chinese annotations and practical notes on this page are written by us.
| Named | Decimal | Hex | Char | Description |
|---|---|---|---|---|
| & | & | & | & | Ampersand; must be escaped in text/attributes |
| < | < | < | < | Less-than; start of a tag, must be escaped |
| > | > | > | > | Greater-than; end of a tag, must be escaped |
| " | " | " | " | Double quotation mark; escape in attribute values |
| ' | ' | ' | ' | Apostrophe; HTML5 ok, not in XML |
| |   |   | Non-breaking space | |
| © | © | © | © | Copyright symbol |
| ® | ® | ® | ® | Registered trademark |
| ™ | ™ | ™ | ™ | Trademark symbol |
| … | … | … | … | Horizontal ellipsis |
| — | — | — | — | Em dash |
| – | – | – | – | En dash |
| € | € | € | € | Euro sign |
| £ | £ | £ | £ | Pound sign |
| ¢ | ¢ | ¢ | ¢ | Cent sign |
| ¥ | ¥ | ¥ | ¥ | Yen / Yuan sign |
| × | × | × | × | Multiplication sign |
| ÷ | ÷ | ÷ | ÷ | Division sign |
| ± | ± | ± | ± | Plus-minus sign |
| ° | ° | ° | ° | Degree sign |
| § | § | § | § | Section sign |
| • | • | • | • | Bullet |
| · | · | · | · | Middle dot |
| « | « | « | « | Left-pointing double angle |
| » | » | » | » | Right-pointing double angle |
| ² | ² | ² | ² | Superscript two |
| ³ | ³ | ³ | ³ | Superscript three |
| ½ | ½ | ½ | ½ | Vulgar fraction one half |
| ∞ | ∞ | ∞ | ∞ | Infinity |
| ≠ | ≠ | ≠ | ≠ | Not equal to |
| ≤ | ≤ | ≤ | ≤ | Less-than or equal to |
| ≥ | ≥ | ≥ | ≥ | Greater-than or equal to |
Frequently Asked Questions
Why use HTML entities?
In HTML, <, >, & and " are reserved characters that would be parsed as tags or entity syntax. Entities such as < let you display the character itself safely.
Named or numeric entities — which is better?
Named entities (e.g. ©) are readable but depend on the spec name table. Numeric entities (© / ©) reference Unicode code points directly, with broader compatibility and safer use in XML.
Do all characters need escaping?
No. Only the reserved characters (& < > " ') and quotes in attribute values need escaping; ordinary prose does not.
Does HTML5 support '?
HTML5 supports ' (apostrophe), but XML/XHTML 1.0 does not; use the numeric entity ' for cross-document safety.