HTML Entities
<, >, &—to mark up tags and other syntax. If you want to display one of those characters literally, or insert a character that's awkward to type directly (a copyright symbol, a non-breaking space), you use an entity instead of the raw character.Two Entity Syntaxes
Entities come in two equivalent forms: a named reference, or a numeric character reference (decimal or hexadecimal).
Form | Syntax | Example |
|---|---|---|
Named entity | &name; | © renders © |
Numeric (decimal) | &#code; | © also renders © |
Numeric (hexadecimal) | ode; | © also renders © |
entity-forms.html
<p>Named: © 2026 Let Codes</p> <p>Decimal: © 2026 Let Codes</p> <p>Hex: © 2026 Let Codes</p> <!-- All three render identically: © 2026 Let Codes -->
Common Entities
Entity | Renders as | Meaning |
|---|---|---|
& | & | Ampersand |
< | < | Less-than sign |
> | Greater-than sign | |
" | " | Double quote |
' | ' | Single quote / apostrophe |
| (a space) | Non-breaking space |
© | © | Copyright symbol |
® | ® | Registered trademark |
™ | ™ | Trademark symbol |
— | — | Em dash |
… | … | Horizontal ellipsis |
When Entities Are Required
required-escaping.html
<!-- Wrong: the parser sees "<3" and tries to interpret it as a tag --> <p>I <3 HTML</p> <!-- Correct --> <p>I <3 HTML</p> <!-- Also required: a literal ampersand not starting another entity --> <p>Terms & Conditions</p>
< must be escaped as < whenever it isn’t starting a real tag.
is technically only required when it could be confused with tag syntax, but escaping it as > is always safe and common practice.
& must be escaped as & whenever it isn’t the start of a real entity, or the parser may misinterpret the following text.
Q&A's raw ampersand followed by a word that happens to match a real entity name can render unexpected characters. Always escape ampersands in plain text to be safe.When Entities Are Optional
©, —, or accented letters such as é don't strictly need an entity; typing them literally works fine in a properly UTF-8-encoded document.optional-entities.html
<!-- Both lines render identically in a UTF-8 document --> <p>Café — small plates, big flavor.</p> <p>Café — small plates, big flavor.</p>
— or can make source code easier to scan than an invisible or easily-mistyped character pasted inline. — A Special Case
inserts a non-breaking space: a space character that prevents a line break at that point. It's commonly used to keep a number and its unit, or a name and title, from wrapping onto separate lines.nbsp.html
<p>The package weighs 4 kg and ships in 2–3 days.</p>
white-space) if you need to preserve multiple visible spaces, rather than stacking several entities.Entities Inside Attribute Values
Entities work inside attribute values too, which matters whenever an attribute's text contains a quote character matching the one used to delimit the attribute.
entities-in-attributes.html
<!-- The title contains a double quote, so it must be escaped --> <abbr title="Rock "n" Roll">R&R</abbr> <!-- Simpler: switch to single quotes for the attribute instead --> <abbr title='Rock "n" Roll'>R&R</abbr>
More Useful Entities
Entity | Renders as | Meaning |
|---|---|---|
– | – | En dash (ranges, e.g. 9–5) |
« | « | Left angle quote |
» | » | Right angle quote |
° | ° | Degree symbol |
€ | € | Euro sign |
£ | £ | Pound sterling sign |
¥ | ¥ | Yen sign |
× | × | Multiplication sign |
÷ | ÷ | Division sign |
Entities vs Escaping in JSX/React
< or curly brace still needs special handling since JSX treats them as syntax. This is worth remembering if you move between plain HTML files and component-based frameworks.Entities come as named (&name;) or numeric (&#code; / ode;) forms—all equivalent.
<, >, and & must be escaped whenever they aren’t part of real markup or a real entity.
Most other special characters are optional to escape in a correctly UTF-8-encoded document.
inserts a non-breaking space to keep related text on the same line.