HTML Character Entities Cheatsheet - HTML Special Characters Reference

In dynamically generated HTML, an unescaped ampersand or angle bracket quietly breaks the document, and in the wrong place it opens an XSS hole. The inverse problem is real too: a wall of & in someone source stops people from reading the template at all. This table classifies entities into basic characters, common symbols, currency, arrows, math, and Greek letters, giving both the named entity and the hexadecimal numeric form for each so you can choose by output target. The rule depends on where the string lands: named entities read better in HTML bodies, numeric &#x...; forms are safer inside JSON, JS strings, and older systems with limited character support, and when the document already declares UTF-8, writing the character directly is usually cleanest for symbols like ©, →, or α. Reach for it when sanitizing user input, assembling email templates, chasing mojibake, or moving a symbol between pages without losing its formatting.

Reference·38 commands·Last updated 2026-07-21
htmlCharacter Entitiesxss

Basic Characters 6

& or &
& ampersand; escape it to show it literally
< or <
< less-than sign
&gt; or &#62;
> greater-than sign
&quot; or &#34;
" double quotation mark
&apos; or &#39;
apostrophe / single quote
&nbsp; or &#160;
Non-breaking space; keeps words on one line

Common Symbols 7

&copy; or &#169;
© copyright sign
&reg; or &#174;
® registered trademark
&trade; or &#8482;
™ trademark sign
&deg; or &#176;
° degree symbol
&plusmn; or &#177;
± plus-minus sign
&times; or &#215;
× multiplication sign
&divide; or &#247;
÷ division sign

Currency Symbols 5

&cent; or &#162;
¢ cent sign
&pound; or &#163;
£ pound sterling sign
&yen; or &#165;
¥ yen / yuan sign
&euro; or &#8364;
€ euro sign
&#8377;
₹ Indian rupee sign

Arrow Symbols 5

&larr; or &#8592;
← leftwards arrow
&uarr; or &#8593;
↑ upwards arrow
&rarr; or &#8594;
→ rightwards arrow
&darr; or &#8595;
↓ downwards arrow
&harr; or &#8596;
↔ left-right arrow

Math Symbols 8

&forall; or &#8704;
∀ universal quantifier, for all
&exist; or &#8707;
∃ existential quantifier, there exists
&infin; or &#8734;
∞ infinity
&sum; or &#8721;
∑ sum summation
&radic; or &#8730;
√ square root (radical)
&ne; or &#8800;
≠ not equal to
&le; or &#8804;
≤ less than or equal to
&ge; or &#8805;
≥ greater than or equal to

Greek Letters 7

&alpha; or &#945;
α Alpha
&beta; or &#946;
β Beta
&gamma; or &#947;
γ Gamma
&delta; or &#948;
δ Delta
&pi; or &#960;
π Pi
&sigma; or &#963;
σ Sigma
&omega; or &#969;
ω Omega

Command Examples

Escape & < > in one fixed order so entities are not re-escaped

const line = 'a<b && c>d; "q"' const safe = line .replace(/&/g, '&amp;') .replace(/</g, '&lt;') .replace(/>/g, '&gt;') console.log(safe)

The ampersand has to be first: if &lt; were replaced before &, the ampersand it introduces would be rewritten again and the page would show &amp;amp; instead of a bracket. The double quote is left alone here because it only needs escaping inside a double-quoted attribute value; for a &quot; delimited attribute you would add one more replacement swapping the quote character for &quot;.

Output

a&lt;b &amp;&amp; c&gt;d; "q"

Reverse direction: decode named and numeric entities back to characters

python -c "import html; print(html.unescape('Tom &amp; Jerry &lt;3 &copy; &#169; &#x3b1; &rarr;'))"

The most useful step when debugging mojibake is to confirm whether it was escaped twice. Both &copy; and &#169; decode to ©, both &alpha; and &#x3b1; decode to α. If literal &amp; text is still on screen after unescape, an upstream layer already escaped once: fix it there instead of decoding a second time here.

Output

Tom & Jerry <3 © © α →

Find a missing semicolon or a bare unescaped & with grep -P

printf 'a &amp; b &copy; c &copy d &euro; ' > page.html grep -oP '&[#a-zA-Z0-9]+;?' page.html grep -nP '&(?!amp;|lt;|gt;|quot;|apos;|nbsp;|copy;|reg;|trade;|deg;|plusmn;|times;|divide;|cent;|pound;|yen;|euro;|larr;|uarr;|rarr;|darr;|harr;|forall;|exist;|infin;|sum;|radic;|ne;|le;|ge;|alpha;|beta;|gamma;|delta;|pi;|sigma;|omega;|#[0-9]+;|#x[0-9a-fA-F]+;)' page.html

The first command lists every entity-shaped fragment so a missing semicolon like &copy stands out. The second is a negative assertion: anything starting with & that is not in the allow-list is either an unknown name, a missing semicolon, or a bare unescaped ampersand. Extend the allow-list with the entities your project actually uses, otherwise valid ones get flagged too.

Output

&amp;
&copy;
&copy
&euro;
1:a &amp; b &copy; c &copy d &euro;

Derive numeric entities from code points, decimal and hex in one pass

node -e " for (const ch of ['©', '€', 'α', '→', '∞']) { console.log(ch, '&#' + ch.codePointAt(0) + ';', '&#x' + ch.codePointAt(0).toString(16) + ';') } "

The decimal forms listed under currency, arrows and Greek letters are produced exactly this way: the code point is the decimal number, and converting that number to hex gives the x form. The code point is the part worth remembering, not the syntax — &copy; equals &#169; and &euro; equals &#8364;, so for a symbol missing from the table, deriving it on the spot beats looking it up.

Output

© &#169; &#xa9;
€ &#8364; &#x20ac;
α &#945; &#x3b1;
→ &#8594; &#x2192;
∞ &#8734; &#x221e;

Common Pitfalls

  • Leaving & < > unescaped lets the data decide the page structure: a single unescaped < in user input can forge a tag or an attribute, which is the canonical XSS entry point.
  • Escape the ampersand first. A per-character pass that handles < before & rewrites the & it just introduced, producing &amp;amp; and literal entity text on screen.
  • Always emit the semicolon in machine-readable output (JSON, JS strings, mail templates); the unterminated &copy form is swallowed or truncated by some older parsers and by any second processing pass.
  • &nbsp; carries the meaning "do not break here", not spacing. Used as margin it scatters layout rules into body text and gets announced by screen readers; use CSS gap or margin for real gaps.
  • Escape once. Running an already-escaped string through the escaper again turns &amp; into &amp;amp;, so check whether an upstream layer already escaped before rendering.

Tips

  • In HTML, < > & must use entities, or they're parsed as tags or entity starts.
  • Numeric entities (&#num;) have broader compatibility; named entities (&name;) read better.
  • To prevent XSS, escape user input into entities before displaying.
  • Modern frameworks (React, Vue) escape by default, but dangerouslySetInnerHTML and v-html need manual handling.

FAQ

Within one batch of HTML, when do I use named entities and when numeric ones?

Decide by output target, not by habit. Named entities (&amp;, &copy;, &rarr;) go in HTML body text: the meaning is spelled out and diffs stay readable. Numeric entities (&#38;, &#169;, &#8594;) go into JSON, JS string literals, or legacy systems with a narrow character set, because they do not depend on the parser knowing a particular name. If the page already declares UTF-8, writing ©, →, α directly is the simplest form and entities are only the fallback.

Why must the ampersand be escaped first?

Because the ampersand is the character that opens every entity, so the replacement has to run in one fixed order: turn every & into &amp; first, then handle &lt; and &gt;. If you replace per character and touch &lt; before &amp;, the text you already produced gets hit again by the next rule and & becomes &amp;amp;, so the page renders a literal &lt; instead of a bracket. Double-escaping user input that was escaped once produces the same pollution.

Can &nbsp; be used as a spacing tool in layout?

No. It is a non-breaking space (&#160;), and its job is to forbid a line break at that position: between a name and its suffix, between a number and its unit, inside short labels that must not wrap. Using it as margin or gap scatters layout rules into body text, and screen readers announce the extra non-breaking space. Use CSS gap or margin for pure visual spacing, and reach for &nbsp; only when a break must be prevented.

What is the risk of writing &amp;copy without the trailing semicolon?

The risk is not modern parsers but mixed sources. The semicolon is the only reliable terminator; HTML5 parsers do fall back for some unterminated forms, but as soon as the text passes through a regex, a template engine, a mail client, or an older XML parser, the missing semicolon can be swallowed as literal text or cut short. The rule is simple: always emit the semicolon in machine-readable output, and if you do omit it in prose, make sure the next character cannot extend the entity name — &amp;copycat would parse as &amp;copy followed by cat.

Beyond &amp; itself, why are &amp;lt; and &amp;gt; mandatory escapes?

They are not typographic characters, they are the syntax of HTML itself. An unescaped &lt; is read as the start of a tag, so the following text either disappears or turns into attributes; an unescaped &gt; can close a tag early in some contexts. The page structure deforms and tag boundaries start being decided by data, which is the classic XSS entry point when user input is concatenated into HTML. Whether &quot; (&#34;) and &apos; (&#39;) must be escaped depends on context: inside a double-quoted attribute value the double quote is mandatory, while a single quote can stay literal inside such an attribute.

Official References

Each command links to its official documentation below, so you can verify the latest usage and read deeper.

Maintained by LaoHand

Publicly updated on Jul 21, 2026, continuously proofread against official docs.

Contact Us

Wrong command or description? Send us corrections, business inquiries or product feedback by email.

Contact Us