Skip to content

/codes/html/html-entities

HTML entities: &, <,  , © and numeric references

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash)updated 2026-10-20
tool
HTML
versions
HTML Living Standard
os
any

An HTML entity (character reference) writes a character as &name;, &#decimal; or &#xhex;. Five characters need escaping in HTML text or attributes because they are part of the syntax: & as &amp;, < as &lt;, > as &gt;, and inside attributes " as &quot; and ' as &#39;. Everything else can be typed directly in a UTF-8 page.

Must-escape characters

CharacterEntityNumericWhy
&&amp;amp;&amp;#38;starts every entity
<&amp;lt;&amp;#60;starts a tag
>&amp;gt;&amp;#62;ends a tag (escape for symmetry)
"&amp;quot;&amp;#34;ends a double-quoted attribute
'&amp;#39; (or &amp;apos;)&amp;#39;ends a single-quoted attribute

Frequently used entities

EntityCharacterName
&amp;nbsp;(no-break space)U+00A0
&amp;copy;©copyright
&amp;reg; / &amp;trade;® / ™registered, trade mark
&amp;euro; / &amp;pound;€ / £currencies
&amp;mdash; / &amp;ndash;— / –dashes
&amp;hellip;…ellipsis
&amp;laquo; / &amp;raquo;« / »angle quotes
&amp;times; / &amp;divide;× / ÷multiplication, division
&amp;rarr; / &amp;larr;→ / ←arrows

Encode and decode them

bash
PYTHONIOENCODING=utf-8 python -c '
import html
print(html.escape("<a href=\"/q?x=1&y=2\">Tom & Jerry</a>"))
print(html.unescape("&copy; 2026 &mdash; caf&eacute; &#x2713; &#8364;"))'

Output

&lt;a href=&quot;/q?x=1&amp;y=2&quot;&gt;Tom &amp; Jerry&lt;/a&gt;
© 2026 — café ✓ €

html.escape escapes quotes by default (quote=True), so its output is safe in attribute values as well as text.

Sources