Skip to content

HTML entity encoder and decoder

Encode text to named or numeric HTML entities and decode them back, with a minimal mode that escapes only the five characters HTML actually requires.

  • Runs in your browser
  • Nothing you enter is sent
  • Free, no account
HTML entities
Encode text so a browser renders it literally, or turn entities back into the characters they stand for.

62 characters

88 characters

Entities written
7
Size change
+26 chars

Minimal mode escapes only & < > " ' — the characters that can break out of element text or an attribute. Everything else, including accents and emoji, is left as literal UTF-8, which is what a modern page wants.

Entity reference
Search by name, character or code point. The first 40 entries are shown until you search.
CharNamedDecimalHexDescription
"&quot;&#34;&#x22;Double quotation mark
&&amp;&#38;&#x26;Ampersand
'&apos;&#39;&#x27;Apostrophe / single quote
<&lt;&#60;&#x3C;Less-than sign — opens a tag
>&gt;&#62;&#x3E;Greater-than sign — closes a tag
 &nbsp;&#160;&#xA0;Non-breaking space
¡&iexcl;&#161;&#xA1;
¢&cent;&#162;&#xA2;
£&pound;&#163;&#xA3;Pound sign
¤&curren;&#164;&#xA4;
¥&yen;&#165;&#xA5;
¦&brvbar;&#166;&#xA6;
§&sect;&#167;&#xA7;
¨&uml;&#168;&#xA8;
©&copy;&#169;&#xA9;Copyright sign
ª&ordf;&#170;&#xAA;
«&laquo;&#171;&#xAB;Left double angle quotation mark
¬&not;&#172;&#xAC;
­&shy;&#173;&#xAD;Soft hyphen — an invisible optional break point
®&reg;&#174;&#xAE;Registered trademark
¯&macr;&#175;&#xAF;
°&deg;&#176;&#xB0;Degree sign
±&plusmn;&#177;&#xB1;
²&sup2;&#178;&#xB2;
³&sup3;&#179;&#xB3;
´&acute;&#180;&#xB4;
µ&micro;&#181;&#xB5;
&para;&#182;&#xB6;
·&middot;&#183;&#xB7;
¸&cedil;&#184;&#xB8;
¹&sup1;&#185;&#xB9;
º&ordm;&#186;&#xBA;
»&raquo;&#187;&#xBB;Right double angle quotation mark
¼&frac14;&#188;&#xBC;
½&frac12;&#189;&#xBD;
¾&frac34;&#190;&#xBE;
¿&iquest;&#191;&#xBF;
À&Agrave;&#192;&#xC0;
Á&Aacute;&#193;&#xC1;
Â&Acirc;&#194;&#xC2;

How to encode and decode entities

  1. Choose Encode to turn characters into entities, or Decode to turn entities back into characters.
  2. Pick the entity style: named (&mdash;), decimal (&#8212;) or hexadecimal (&#x2014;).
  3. Choose how much to escape. Only special characters is the right answer for almost every modern page.
  4. Copy the result, or use the reference table to look up a single character.

Which characters actually need escaping

Fewer than people think. HTML only needs escaping where a character would otherwise be read as markup, and that depends on where the text sits.

ContextMust escapeWhy
Element text& and << opens a tag; & starts an entity
Double-quoted attribute& and "The quote would close the attribute early
Single-quoted attribute& and 'Same reason
Unquoted attributeAlmost everythingDo not use unquoted attributes with dynamic values

Most libraries escape all five of & < > " ' regardless of context, because it is cheap and it stops a value being moved from one context to another later. That is what minimal mode does here.

Named, decimal or hexadecimal?

All three produce the same character. Named references are readable — &nbsp; tells you more than &#160; — but there are over 2000 of them, only HTML defines them (XML knows just five), and older parsers disagree on the edges. Numeric references work everywhere and need no lookup table. Hexadecimal is the usual choice when you are copying a code point straight out of the Unicode charts, where they are written as U+2014.

If your page is served as UTF-8, which it should be, the best answer for most characters is neither: just write the character. — is one byte cheaper than &mdash;, easier to read in source, and searchable in your editor.

Entities you will actually meet

CharacterNamedNumericNotes
&&amp;&#38;Escape it first, or you will double-encode everything else
<&lt;&#60;The one that actually opens a tag
>&gt;&#62;Not strictly required in text, escaped by convention
"&quot;&#34;Required inside double-quoted attributes
'&apos;&#39;&apos; is HTML5 and XML; older HTML only had the numeric form
non-breaking space&nbsp;&#160;Prevents a line break; not the same character as a normal space
—&mdash;&#8212;Em dash
–&ndash;&#8211;En dash, for ranges
…&hellip;&#8230;A single ellipsis character, not three dots
©&copy;&#169;
€&euro;&#8364;

Escaping is not the whole of XSS defence

HTML escaping stops text being reinterpreted as markup, which handles the classic <script> injection into element text. It does not protect other contexts. A value dropped inside a <script> block needs JavaScript string escaping; a value used as an href needs a scheme allowlist (javascript: URLs are not markup and survive HTML escaping untouched); a value inside a style attribute needs CSS escaping. Use a templating engine that knows the context, and treat this tool as a debugging aid rather than a security control.

Astral characters and emoji

Characters above U+FFFF are stored in JavaScript as two UTF-16 code units. Encoders that iterate over code units split them and produce two meaningless references. This tool iterates by code point, so 😀 becomes the single reference &#128512; and decodes back to the same emoji.

Questions

Which characters actually need escaping in HTML?

In element text, only the ampersand and the less-than sign. Inside a double-quoted attribute, the double quote as well. Most people escape ampersand, both angle brackets and both quote characters for safety, which is exactly what the minimal mode does.

Named or numeric entities — which should I use?

Numeric references such as &#8212; work in every parser and need no entity table. Named ones such as &mdash; are more readable. Both are decoded here; pick whichever your codebase already uses.

Does escaping HTML make my page safe from XSS?

Escaping is necessary but not sufficient. It stops text being read as markup, but a value placed inside a script block, an inline event handler or a URL attribute needs its own context-specific escaping too.

How are emoji and other astral characters handled?

They are treated as whole code points, not as UTF-16 halves, so an emoji becomes a single numeric reference like &#128512; and round-trips back to the same character.