Developer Tools

HTML Entity Encoder/Decoder

Convert text to HTML entities or decode entities back. Named + numeric. 80+ common entity reference.

Common entities reference
NameCharNamedNumeric
Ampersand&&&
Less than<&lt;&#60;
Greater than>&gt;&#62;
Double quote"&quot;&#34;
Apostrophe'&apos;&#39;
Non-breaking space &nbsp;&#160;
Copyright©&copy;&#169;
Registered®&reg;&#174;
Trademark&trade;&#8482;
Em dash&mdash;&#8212;
En dash&ndash;&#8211;
Ellipsis&hellip;&#8230;
Left single quote&lsquo;&#8216;
Right single quote&rsquo;&#8217;
Left double quote&ldquo;&#8220;
Right double quote&rdquo;&#8221;
Degree°&deg;&#176;
Plus-minus±&plusmn;&#177;
Times×&times;&#215;
Divide÷&divide;&#247;
Cent¢&cent;&#162;
Pound£&pound;&#163;
Euro&euro;&#8364;
Yen¥&yen;&#165;
Left arrow&larr;&#8592;
Right arrow&rarr;&#8594;

What HTML entities are for

HTML uses certain characters as syntax: < opens a tag, > closes one, & introduces an entity. To put these characters in text content (rather than markup), you encode them as entities. Without encoding, the browser would try to interpret them as HTML.

Five characters always need encoding in HTML body: &, <, >, ", ' (the last two only matter in attribute values). Beyond those, encoding is optional but useful for readability of non-typeable characters (em dashes, copyright, accented letters).

Named vs numeric entities

Three forms for the copyright symbol:

  • Named: &copy; — readable but only ~250 are predefined in HTML.
  • Numeric decimal: &#169; — universal, works for any Unicode codepoint.
  • Numeric hexadecimal: &#xA9; — same as decimal but in hex (matches Unicode notation).

All three render identically. Named entities are easier to read, numeric entities are more portable. Modern HTML5 supports thousands of named entities.

When to encode

  • Outputting user-generated content: critical to prevent XSS. Always encode before injecting into HTML.
  • Attribute values: encode quotes (&quot; in double-quoted attributes, &apos; in single-quoted).
  • Embedding HTML in other HTML: like showing code samples on a tutorial site.
  • Serializing XML/HTML for storage or transport.

When NOT to encode

  • JavaScript context (e.g., embedded in onclick or <script> blocks): use JavaScript escaping instead. HTML entities aren't parsed inside <script>.
  • JSON: JSON has its own escaping rules (\", \\, \\n). Don't HTML-encode JSON.
  • URLs: use URL percent-encoding (URL Encoder/Decoder), not HTML entities.
  • CSS: CSS has its own escaping (\\ + hex). Don't mix.

Common entities you should memorize

  • &amp; — & (always encode in HTML body)
  • &lt; / &gt; — < and >
  • &quot; — " (in attribute values)
  • &nbsp; — non-breaking space
  • &copy; — © (copyright)
  • &mdash; / &ndash; — — and –
  • &hellip; — …
  • &ldquo; / &rdquo; — “ and ” (smart quotes)
  • &times; / &divide; — × and ÷

Security: when entities save you

XSS (cross-site scripting) attacks work by tricking your site into rendering attacker-controlled JavaScript. The basic defense: HTML-encode user input before placing it in HTML output. <script>alert(1)</script> becomes harmless text after encoding the angle brackets.

But: encoding ONLY for HTML body context. Different contexts need different escaping. Use a templating library (React, Vue, Angular, Django templates, Rails ERB with auto-escape) — they handle context-aware escaping automatically. Hand-rolling it for production is risky.

For other text/encoding tools: URL Encoder/Decoder, Base64 Encoder/Decoder, and JSON Formatter.

Frequently Asked Questions

What are HTML entities?
Special character sequences that represent reserved or non-typeable characters in HTML. They start with & and end with ;. The most important ones: &amp; for &, &lt; for <, &gt; for >, &quot; for ", &nbsp; for non-breaking space. Without them, you can't safely include HTML markup as text.
Named entities vs numeric entities — which to use?
Named entities (&copy;) are more readable. Numeric entities (&#169; or &#xA9;) are universal — work in older browsers and in contexts where named entities might not be defined. For modern HTML5, both work fine. For XML, only the five core named entities (amp, lt, gt, quot, apos) are predefined.
Does this protect against XSS?
Encoding the five HTML-special characters (&, <, >, ", ') prevents user-supplied text from breaking out of HTML context — the foundation of XSS prevention. But context matters: encoding for HTML body is different from attribute, JavaScript, CSS, or URL contexts. Use a vetted templating library (React, Vue, etc.) for production XSS prevention.
What's &nbsp; for?
&nbsp; is a non-breaking space — visually identical to a normal space but doesn't allow line breaks at that point. Used to keep words together (e.g., "Mr.&nbsp;Smith") or to add minimum spacing in old-school HTML. In modern CSS, white-space: nowrap or word-spacing achieves the same goal more cleanly.
Can I use entities in attributes?
Yes. <a href="?q=1&amp;p=2"> is the right way to put a literal & in an attribute value. Browsers parse entities everywhere in HTML — in body text, attribute values, and even in some script contexts (though scripts have their own escaping rules).

Related Calculators