79 entries

HTML Entities

An HTML entity is a way of writing a character using only ASCII, either by name (©) or by code point (©). Only five are strictly required — the reserved characters that would otherwise be read as markup. The rest exist for convenience, and on a UTF-8 page you can usually type the character directly instead.

Entities solved a problem that has largely gone away. When pages were served in ASCII or Latin-1, an entity was the only way to write a curly quote or an em dash. On a modern UTF-8 page you can type those characters directly, and the file will be smaller and easier to read for it.

What has not gone away is the need to escape the reserved characters. A stray < or & is not a display bug — it is a parsing bug, and in the wrong place it is an injection vulnerability. Those five entities are the ones that matter; everything below them is convenience.

Reserved characters

5 entries

The only entities you genuinely need. These characters have meaning in markup, so writing them literally changes how the document parses.

Character Named Numeric Escape it when
& &amp; &#38; Always. An unescaped ampersand starts an entity, so &copy in text may render as ©.
< &lt; &#60; Always in text content. An unescaped less-than sign starts a tag.
> &gt; &#62; In text content. Less critical than < but conventional, and required inside some contexts.
" &quot; &#34; Inside a double-quoted attribute value, where it would end the attribute.
' &apos; &#39; Inside a single-quoted attribute value. Use &#39; for older HTML, where &apos; was not defined.

Spaces and typography

22 entries

Punctuation a word processor substitutes automatically, and the space variants that behave differently from a plain space.

Character Named Numeric Notes
(space) &nbsp; &#160; Non-breaking space. Prevents a line break and stops whitespace collapsing. Overuse for layout is a common mistake.
(space) &ensp; &#8194; En space — the width of an en dash.
(space) &emsp; &#8195; Em space — the width of an em dash.
(none) &shy; &#173; Soft hyphen. Invisible until the word wraps at that point.
(none) &zwnj; &#8204; Zero-width non-joiner. Invisible, and a frequent cause of strings that look equal but are not.
&ndash; &#8211; En dash. Ranges: 2020–2024.
&mdash; &#8212; Em dash. Parenthetical breaks in a sentence.
&hellip; &#8230; Horizontal ellipsis — one character, not three full stops.
&lsquo; &#8216; Left single quote, also used as an apostrophe in typeset text.
&rsquo; &#8217; Right single quote. The correct apostrophe character.
&ldquo; &#8220; Left double quote.
&rdquo; &#8221; Right double quote.
« &laquo; &#171; Left guillemet, used as a quotation mark in French and other languages.
» &raquo; &#187; Right guillemet.
&bull; &#8226; Bullet.
· &middot; &#183; Middle dot, often used as a separator in navigation.
&dagger; &#8224; Dagger — footnote marker.
&Dagger; &#8225; Double dagger.
&para; &#182; Pilcrow — paragraph mark.
§ &sect; &#167; Section sign.
&prime; &#8242; Prime — minutes, feet. Not an apostrophe.
&Prime; &#8243; Double prime — seconds, inches.

Currency and legal

10 entries

Symbols that appear constantly in commercial copy.

Character Named Numeric Notes
£ &pound; &#163; Pound sterling.
&euro; &#8364; Euro.
¥ &yen; &#165; Yen or yuan.
¢ &cent; &#162; Cent.
¤ &curren; &#164; Generic currency sign.
© &copy; &#169; Copyright.
® &reg; &#174; Registered trademark.
&trade; &#8482; Trademark.
&#8480; &#8480; Service mark. No named entity.
° &deg; &#176; Degree — temperature and angles.

Mathematical and technical

18 entries

Operators and symbols that are not on a standard keyboard.

Character Named Numeric Notes
× &times; &#215; Multiplication sign. Use this rather than the letter x for dimensions.
÷ &divide; &#247; Division sign.
± &plusmn; &#177; Plus-minus.
&minus; &#8722; True minus sign, wider than a hyphen.
&ne; &#8800; Not equal to.
&le; &#8804; Less than or equal to.
&ge; &#8805; Greater than or equal to.
&asymp; &#8776; Approximately equal to.
&infin; &#8734; Infinity.
&radic; &#8730; Square root.
&sum; &#8721; Summation.
&prod; &#8719; Product.
&int; &#8747; Integral.
&part; &#8706; Partial differential.
½ &frac12; &#189; One half.
¼ &frac14; &#188; One quarter.
¾ &frac34; &#190; Three quarters.
µ &micro; &#181; Micro sign. Distinct from the Greek letter mu, though they look alike.

Arrows

9 entries

Common in navigation, diagrams and documentation.

Character Named Numeric Notes
&larr; &#8592; Left arrow.
&rarr; &#8594; Right arrow.
&uarr; &#8593; Up arrow.
&darr; &#8595; Down arrow.
&harr; &#8596; Left-right arrow.
&lArr; &#8656; Double left arrow.
&rArr; &#8658; Double right arrow — often read as "implies".
&hArr; &#8660; Double left-right arrow — "if and only if".
&crarr; &#8629; Carriage return arrow.

Greek letters

15 entries

Used in mathematics, science and engineering notation.

Character Named Numeric Notes
α &alpha; &#945; Alpha.
β &beta; &#946; Beta.
γ &gamma; &#947; Gamma.
δ &delta; &#948; Delta.
Δ &Delta; &#916; Capital delta — change or difference.
ε &epsilon; &#949; Epsilon.
θ &theta; &#952; Theta.
λ &lambda; &#955; Lambda.
μ &mu; &#956; Mu. For the micro prefix, &micro; is the correct character.
π &pi; &#960; Pi.
σ &sigma; &#963; Sigma.
Σ &Sigma; &#931; Capital sigma. For summation, &sum; is the correct character.
φ &phi; &#966; Phi.
ω &omega; &#969; Omega.
Ω &Omega; &#937; Capital omega — ohms.

Notes

  • Every entity has a numeric form, and numeric forms always work. Named entities are more readable but the set is large and support for the more obscure names has historically been uneven, which is why numeric references are the safer choice in email templates.
  • XML predefines only five entities — &amp;lt; &amp;gt; &amp;amp; &amp;quot; and &amp;apos; — so &amp;nbsp; in an XML document is an error unless a DTD declares it. Use the numeric form &amp;#160; instead.
  • Escaping is contextual. Escaping for HTML text is not the same as escaping for an attribute, a URL, JavaScript or CSS, and applying the wrong one leaves a hole. Escape at the point of output, for the context it is being written into.

Frequently asked questions

Which entities do I actually have to use?
On a UTF-8 page, only the reserved characters: &amp; and &lt; always, &gt; by convention, and the quote characters inside matching attribute quotes. Everything else can be typed directly, and the file is smaller and more readable for it.
Should I use named or numeric references?
Named for the five reserved characters — they are universally supported and far more readable. Numeric for anything unusual, and in email templates, where client support for the longer names is inconsistent.
Why does &amp;nbsp; break my XML or RSS feed?
Because XML defines only five entities and nbsp is not among them. HTML gets its longer list from the HTML specification, which XML does not inherit. Use &amp;#160; in XML.
Is escaping HTML enough to prevent XSS?
Only for text content. An attribute, a URL, a JavaScript string and a CSS value each need their own escaping, and HTML-escaping a value that lands in a script tag does not make it safe. Escape at output, appropriate to the context.
Why do non-breaking spaces cause problems?
They look identical to a normal space but are a different character, so exact-match comparisons, searches and imports fail on them. Text pasted from a web page or word processor routinely carries them, which is why cleaning pasted text is worth doing.

Related tools

All tools →
All references →

Last reviewed .