HTML entity encode & decode

Escape text so it displays literally in HTML, or turn entities like < and é back into characters.

Which characters must be escaped?

In element content you must escape < and &. Inside attribute values also escape the quote character you used. Escaping >, " and ' everywhere is a safe habit and prevents most HTML injection bugs.

CharNamedDecimalHex
<&lt;&#60;&#x3C;
>&gt;&#62;&#x3E;
&&amp;&#38;&#x26;
"&quot;&#34;&#x22;
'&apos;&#39;&#x27;
non-breaking space&nbsp;&#160;&#xA0;
©&copy;&#169;&#xA9;
€&euro;&#8364;&#x20AC;

See the ASCII table for the numeric entity of every basic character.

Frequently asked questions

Do I need entities for accented letters?
Not if your page is served as UTF-8 (<meta charset="utf-8">). Entities are still handy when you cannot control the encoding.
Is escaping enough to stop XSS?
Escaping is required for text in HTML content and quoted attributes, but URLs, inline scripts and CSS need their own context-specific encoding.