HTML Entity Encoder/Decoder

HTML encoding converts special characters to entities to prevent XSS attacks and display literal text. Essential conversions: < becomes &lt;, > becomes &gt;, & becomes &amp;, " becomes &quot;, ' becomes &#39;. For example, <script>alert("XSS")</script> encodes to &lt;script&gt;alert(&quot;XSS&quot;)&lt;/script&gt;. Always encode user input before displaying in HTML. URL encoding differs: spaces become %20, & becomes %26. Use HTML encoding for content, URL encoding for query parameters.

Encode special characters to HTML entities or decode HTML entities back to characters. Supports named entities (&amp;), numeric entities (&#38;), and hexadecimal entities (&#x26;).

Works OfflineDark ModeNo Ads

Text to Encode

Encoded Result

Common HTML Entities Reference

CharNamedNumericHexDescription
&&amp;&#38;&#x26;Ampersand
<&lt;&#60;&#x3C;Less than
>&gt;&#62;&#x3E;Greater than
"&quot;&#34;&#x22;Double quote
'&#39;&#39;&#x27;Single quote
(space)&nbsp;&#160;&#xA0;Non-breaking space
©&copy;&#169;&#xA9;Copyright
®&reg;&#174;&#xAE;Registered
&trade;&#8482;&#x2122;Trademark
&euro;&#8364;&#x20AC;Euro sign
£&pound;&#163;&#xA3;Pound sign
&mdash;&#8212;&#x2014;Em dash
&ndash;&#8211;&#x2013;En dash
&bull;&#8226;&#x2022;Bullet
&hellip;&#8230;&#x2026;Ellipsis

About HTML Entities

  • Named entities: Human-readable, like &amp; for &
  • Numeric entities: Decimal code points, like &#38; for &
  • Hex entities: Hexadecimal code points, like &#x26; for &
  • Why encode? Prevents HTML injection and displays special characters correctly

How to Use

  1. Enter your value in the input field
  2. Click the Calculate/Convert button
  3. Copy the result to your clipboard

Frequently Asked Questions

What are HTML entities?
HTML entities are special codes used to display reserved characters, symbols, and special characters in HTML. Named entities use names like &amp; (ampersand), &lt; (less than), &gt; (greater than). Numeric entities use decimal &#38; or hex &#x26; codes. They prevent HTML from misinterpreting characters as markup and allow displaying characters not on the keyboard.
Why do I need to encode HTML?
HTML encoding is essential to prevent breaking markup and protect against XSS (Cross-Site Scripting) attacks. Characters like <, >, &, and quotes have special meaning in HTML. For example, displaying <script> literally requires encoding it as &lt;script&gt; — otherwise the browser treats it as actual JavaScript. Always encode user input before displaying it in HTML.
What characters need HTML encoding?
Five characters must always be encoded in HTML content: & (&amp;), < (&lt;), > (&gt;), " (&quot; in attributes), and ' (&#39; in attributes). Additionally, encode non-breaking spaces (&nbsp;), copyright symbols (&copy;), and other special characters like é (&eacute;), — (&mdash;), and • (&bull;).
What is the difference between named and numeric entities?
Named entities use memorable names: &copy; for ©, &euro; for €, &nbsp; for non-breaking space. Numeric entities use character codes: &#169; (decimal) or &#xA9; (hexadecimal) for ©. Named entities are more readable but not all characters have names. Numeric entities work for any Unicode character. Both are decoded identically by browsers.
How do I decode HTML entities in JavaScript?
In the browser, create a temporary element: const el = document.createElement('div'); el.innerHTML = '&lt;p&gt;Hello&lt;/p&gt;'; const decoded = el.textContent; returns "<p>Hello</p>". Or use DOMParser: new DOMParser().parseFromString(text, 'text/html').documentElement.textContent. For Node.js, use the html-entities library or he package.
Do I need to encode HTML in JSON?
No, JSON does not interpret HTML tags or entities — it is a pure data format. HTML entities like &lt; will be stored literally as the string "&lt;" in JSON. However, if you will insert JSON data into HTML (e.g., innerHTML or dangerouslySetInnerHTML in React), encode it then. Encode at the point of rendering, not during JSON serialization.
What is the difference between HTML encoding and URL encoding?
HTML encoding converts characters to HTML entities (&lt;, &amp;) for safe display in HTML documents. URL encoding converts characters to percent-encoded format (%20 for space, %3C for <) for safe use in URLs. They serve different purposes: HTML encoding prevents markup interpretation, URL encoding makes URLs valid. Use HTML encoding for content, URL encoding for query strings and paths.
Are HTML entities case-sensitive?
Named HTML entities are case-sensitive: &Amp; is invalid; only &amp; works. &Copy; will not render ©; you must use &copy;. However, the HTML specification is lenient — browsers may auto-correct common mistakes. Numeric entities (&#169;, &#xA9;) are not case-sensitive for the hex prefix: both &#xA9; and &#XA9; work, as do &#xa9; and &#Xa9;.

Related Tools