HTMLHTML Entities & Special Characters

HTML Entities

HTML reserves a handful of characters—<, >, &—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;

&copy; renders ©

Numeric (decimal)

&#code;

&#169; also renders ©

Numeric (hexadecimal)

&#xcode;

&#xA9; also renders ©

entity-forms.html

HTML
<p>Named: &copy; 2026 Let Codes</p>
<p>Decimal: &#169; 2026 Let Codes</p>
<p>Hex: &#xA9; 2026 Let Codes</p>
<!-- All three render identically: © 2026 Let Codes -->
Common Entities

Entity

Renders as

Meaning

&amp;

&

Ampersand

&lt;

<

Less-than sign

&gt;

Greater-than sign

&quot;

"

Double quote

&apos;

'

Single quote / apostrophe

&nbsp;

(a space)

Non-breaking space

&copy;

©

Copyright symbol

&reg;

®

Registered trademark

&trade;

Trademark symbol

&mdash;

Em dash

&hellip;

Horizontal ellipsis

When Entities Are Required
Three characters are effectively required to be escaped as entities whenever they appear as literal text, because the raw character would otherwise be parsed as markup.

required-escaping.html

HTML
<!-- Wrong: the parser sees "<3" and tries to interpret it as a tag -->
<p>I <3 HTML</p>

<!-- Correct -->
<p>I &lt;3 HTML</p>

<!-- Also required: a literal ampersand not starting another entity -->
<p>Terms &amp; 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.

An unescaped & can silently break rendering
Browsers are lenient about malformed entities, but writing something like 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
Most other special characters can be typed directly into your HTML source as long as the file is saved with correct encoding (UTF-8—see the next lesson). Characters like ©, , 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

HTML
<!-- Both lines render identically in a UTF-8 document -->
<p>Caf&eacute; — small plates, big flavor.</p>
<p>Café — small plates, big flavor.</p>
Use entities for source clarity, not just necessity
Even when a character could be typed directly, an entity like &mdash; or &nbsp; can make source code easier to scan than an invisible or easily-mistyped character pasted inline.
&nbsp; — A Special Case
&nbsp; 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

HTML
<p>The package weighs 4&nbsp;kg and ships in 2&ndash;3&nbsp;days.</p>
Multiple consecutive spaces still collapse
HTML collapses runs of whitespace to a single space by default, even with entities—use CSS (white-space) if you need to preserve multiple visible spaces, rather than stacking several &nbsp; 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

HTML
<!-- The title contains a double quote, so it must be escaped -->
<abbr title="Rock &quot;n&quot; Roll">R&amp;R</abbr>

<!-- Simpler: switch to single quotes for the attribute instead -->
<abbr title='Rock "n" Roll'>R&amp;R</abbr>
More Useful Entities

Entity

Renders as

Meaning

&ndash;

En dash (ranges, e.g. 9–5)

&laquo;

«

Left angle quote

&raquo;

»

Right angle quote

&deg;

°

Degree symbol

&euro;

Euro sign

&pound;

£

Pound sterling sign

&yen;

¥

Yen sign

&times;

×

Multiplication sign

&divide;

÷

Division sign

Entities vs Escaping in JSX/React
If you're writing HTML-like markup inside JSX (as in React templates), the rules differ slightly: JSX already escapes text content automatically, but a literal < 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; / &#xcode;) 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.