HTML entity encoder and decoder

HTML entities are codes like &lt; for < that let a page show characters the browser would otherwise read as markup. Paste text to encode the characters HTML reserves, and optionally everything outside ASCII, or paste entities to decode them back.

Covers the 148 names in this page's table; other characters follow the setting above.

Encoded HTML

&lt;p&gt;Fish &amp; chips for ₹250 — &quot;today&quot; only, at Raj&#39;s&lt;/p&gt;
Characters replaced
8 of 53& ×1, < ×2, > ×2, " ×2, ' ×1
Length
53 → 83 characters
  • This output is safe as text between tags. Inside an attribute, also put the value in quotes; inside <script>, a style, an event handler such as onclick, or a URL, HTML entities aren't enough and that context needs its own encoding.

How does HTML entity encoding work?

A character reference starts with & and ends with a semicolon. HTML has three forms: a name from its named character references list (&amp;), a decimal code point after &# (&#38;), or a hex code point after &#x (&#x26;). All three mean the same character, and the HTML standard requires the closing semicolon.

Encoding replaces the characters that HTML would read as markup. & starts a reference and < starts a tag, so they must be encoded in text; >, " and ' are encoded too, so the same output also works inside a quoted text attribute such as title or alt. The apostrophe has three spellings: &#39; and &#x27; work everywhere, and &apos; is in the HTML standard's named list but was not defined in HTML 4.01.

Characters outside ASCII don't need encoding on a modern page: the HTML standard requires documents to be encoded in UTF-8, so é, ₹ and emoji can be typed as they are. Numeric references help when text passes through a system that isn't UTF-8, or to make invisible characters such as the no-break space visible in the source. There is no named reference for ₹, so it is &#8377; or &#x20B9;.

Encoding is for the HTML context only. OWASP's cross-site scripting cheat sheet uses this encoding for text placed in HTML, says attribute values should always be quoted, and says JavaScript, CSS and URL contexts need their own encoding. Decoding here covers the 148 common names in this page's table and every decimal and hex reference; anything else is left as typed and listed under the result.

Numeric references are read the way the HTML standard tells browsers to read them: numbers 128 to 159 are taken as Windows-1252 characters, so &#150; is – and &#128; is €. References to zero, to a surrogate or to a number past U+10FFFF are left as typed and flagged, because a browser would show the replacement character � for them.

&  →  &amp;      <  →  &lt;      >  →  &gt;
"  →  &quot;     '  →  &#39;  (or &apos; or &#x27;)
any character  →  &#decimal;  or  &#xHEX;
₹ (U+20B9)  →  &#8377;  =  &#x20B9;

What are the HTML entities for common characters?

Named, decimal and hex references for the characters HTML reserves and some common symbols (“none” means HTML has no name for it)
CharacterNamedDecimalHex
&&amp;&#38;&#x26;
<&lt;&#60;&#x3C;
>&gt;&#62;&#x3E;
"&quot;&#34;&#x22;
'&apos;&#39;&#x27;
(no-break space)&nbsp;&#160;&#xA0;
©&copy;&#169;&#xA9;
®&reg;&#174;&#xAE;
™&trade;&#8482;&#x2122;
€&euro;&#8364;&#x20AC;
£&pound;&#163;&#xA3;
¥&yen;&#165;&#xA5;
₹none&#8377;&#x20B9;
—&mdash;&#8212;&#x2014;
–&ndash;&#8211;&#x2013;
…&hellip;&#8230;&#x2026;
“&ldquo;&#8220;&#x201C;
”&rdquo;&#8221;&#x201D;
é&eacute;&#233;&#xE9;
×&times;&#215;&#xD7;
→&rarr;&#8594;&#x2192;

How to encode or decode HTML entities

  1. 1
    Choose encode or decodeEncode turns text into something a page shows literally; decode turns &lt;, &#8377; and similar references back into characters.
  2. 2
    Paste your textPaste the text or HTML. The result updates as you type, and nothing is sent anywhere.
  3. 3
    Pick the optionsWhen encoding, choose how to write the apostrophe, whether to encode characters outside ASCII as decimal or hex references, and whether to use names such as &copy;.
  4. 4
    Copy the resultCopy the output. Any reference that couldn't be decoded is listed under it with the reason.

Frequently asked questions

What is the difference between &#39; and &apos;?
Nothing on a modern page: both are the apostrophe ('). &apos; is in the HTML standard's named character references and in XML, but HTML 4.01 didn't define it, so &#39; is the choice that works everywhere. OWASP's cross-site scripting cheat sheet writes it as &#x27;.
Is there an HTML entity for the rupee sign (₹)?
Not a named one: the HTML standard's list has no &rupee; or &INR;. Use the numeric references &#8377; or &#x20B9; (U+20B9), or type ₹ directly, since HTML pages must be UTF-8.
Does encoding HTML entities prevent XSS?
Only for text placed between HTML tags, and inside quoted attribute values. OWASP's cheat sheet says event handlers such as onclick, script blocks, CSS and URLs need their own encoding or validation, and that output encoding alone won't always prevent XSS. Use your framework's escaping and avoid putting user input in those places.
Why does my page show an entity code where an ampersand should be?
The text was encoded twice: once into &amp;, then that & was encoded again, so the page prints the code instead of the character. Decode it once to see what was stored, then find the step that escapes it a second time, often a template that escapes by default plus code that escaped it already.
Do I need to encode accented letters and emoji in HTML?
No. The HTML standard requires pages to be encoded in UTF-8, so é, ₹ and emoji can be written directly. Only &, < and the quote characters need encoding; numeric references are useful for invisible characters or text that passes through a system that isn't UTF-8.

Sources

Related tools

See all 73 free tools

Need a custom dev tool for your team?

We build internal tools, dashboards, APIs, and SaaS platforms. If you can describe it, we can ship it.

Built by CountryDevs · No signup · No ads · We count visits, never what you enter