HTML Entity Encoder/Decoder

Encode and decode HTML entities with XSS detection, entity reference, and code snippets. All client-side.

Plain Text / HTML
Encoded Output
Rendered Preview
<h1>Hello & "World"</h1>
Entity Reference (151)
CharNamedDecimalHexCategory
&&&&Basic
<&lt;&#60;&#x3C;Basic
>&gt;&#62;&#x3E;Basic
"&quot;&#34;&#x22;Basic
'&apos;&#39;&#x27;Basic
&nbsp;&#160;&#xA0;Basic
©&copy;&#169;&#xA9;Basic
®&reg;&#174;&#xAE;Basic
&trade;&#8482;&#x2122;Basic
&bull;&#8226;&#x2022;Basic
&hellip;&#8230;&#x2026;Basic
&mdash;&#8212;&#x2014;Basic
&ndash;&#8211;&#x2013;Basic
'&lsquo;&#8216;&#x2018;Basic
'&rsquo;&#8217;&#x2019;Basic
&ldquo;&#8220;&#x201C;Basic
&rdquo;&#8221;&#x201D;Basic
§&sect;&#167;&#xA7;Basic
&para;&#182;&#xB6;Basic
&dagger;&#8224;&#x2020;Basic
&Dagger;&#8225;&#x2021;Basic
&larr;&#8592;&#x2190;Arrows
&uarr;&#8593;&#x2191;Arrows
&rarr;&#8594;&#x2192;Arrows
&darr;&#8595;&#x2193;Arrows
&harr;&#8596;&#x2194;Arrows
&crarr;&#8629;&#x21B5;Arrows
&lArr;&#8656;&#x21D0;Arrows
&uArr;&#8657;&#x21D1;Arrows
&rArr;&#8658;&#x21D2;Arrows
&dArr;&#8659;&#x21D3;Arrows
&hArr;&#8660;&#x21D4;Arrows
&forall;&#8704;&#x2200;Math
&part;&#8706;&#x2202;Math
&exist;&#8707;&#x2203;Math
&empty;&#8709;&#x2205;Math
&nabla;&#8711;&#x2207;Math
&isin;&#8712;&#x2208;Math
&notin;&#8713;&#x2209;Math
&ni;&#8715;&#x220B;Math
&prod;&#8719;&#x220F;Math
&sum;&#8721;&#x2211;Math
&minus;&#8722;&#x2212;Math
&lowast;&#8727;&#x2217;Math
&radic;&#8730;&#x221A;Math
&prop;&#8733;&#x221D;Math
&infin;&#8734;&#x221E;Math
&ang;&#8736;&#x2220;Math
&and;&#8743;&#x2227;Math
&or;&#8744;&#x2228;Math
&cap;&#8745;&#x2229;Math
&cup;&#8746;&#x222A;Math
&int;&#8747;&#x222B;Math
&asymp;&#8776;&#x2248;Math
&ne;&#8800;&#x2260;Math
&equiv;&#8801;&#x2261;Math
&le;&#8804;&#x2264;Math
&ge;&#8805;&#x2265;Math
&sub;&#8834;&#x2282;Math
&sup;&#8835;&#x2283;Math
&sube;&#8838;&#x2286;Math
&supe;&#8839;&#x2287;Math
&oplus;&#8853;&#x2295;Math
&otimes;&#8855;&#x2297;Math
×&times;&#215;&#xD7;Math
÷&divide;&#247;&#xF7;Math
±&plusmn;&#177;&#xB1;Math
¼&frac14;&#188;&#xBC;Math
½&frac12;&#189;&#xBD;Math
¾&frac34;&#190;&#xBE;Math
¢&cent;&#162;&#xA2;Currency
£&pound;&#163;&#xA3;Currency
¥&yen;&#165;&#xA5;Currency
&euro;&#8364;&#x20AC;Currency
¤&curren;&#164;&#xA4;Currency
&#8377;&#8377;&#x20B9;Currency
&#8361;&#8361;&#x20A9;Currency
&#8383;&#8383;&#x20BF;Currency
α&alpha;&#945;&#x3B1;Greek
β&beta;&#946;&#x3B2;Greek
γ&gamma;&#947;&#x3B3;Greek
δ&delta;&#948;&#x3B4;Greek
ε&epsilon;&#949;&#x3B5;Greek
ζ&zeta;&#950;&#x3B6;Greek
η&eta;&#951;&#x3B7;Greek
θ&theta;&#952;&#x3B8;Greek
ι&iota;&#953;&#x3B9;Greek
κ&kappa;&#954;&#x3BA;Greek
λ&lambda;&#955;&#x3BB;Greek
μ&mu;&#956;&#x3BC;Greek
ν&nu;&#957;&#x3BD;Greek
ξ&xi;&#958;&#x3BE;Greek
ο&omicron;&#959;&#x3BF;Greek
π&pi;&#960;&#x3C0;Greek
ρ&rho;&#961;&#x3C1;Greek
σ&sigma;&#963;&#x3C3;Greek
τ&tau;&#964;&#x3C4;Greek
υ&upsilon;&#965;&#x3C5;Greek
φ&phi;&#966;&#x3C6;Greek
χ&chi;&#967;&#x3C7;Greek
ψ&psi;&#968;&#x3C8;Greek
ω&omega;&#969;&#x3C9;Greek
Α&Alpha;&#913;&#x391;Greek
Β&Beta;&#914;&#x392;Greek
Γ&Gamma;&#915;&#x393;Greek
Δ&Delta;&#916;&#x394;Greek
Ε&Epsilon;&#917;&#x395;Greek
Ζ&Zeta;&#918;&#x396;Greek
Η&Eta;&#919;&#x397;Greek
Θ&Theta;&#920;&#x398;Greek
Ι&Iota;&#921;&#x399;Greek
Κ&Kappa;&#922;&#x39A;Greek
Λ&Lambda;&#923;&#x39B;Greek
Μ&Mu;&#924;&#x39C;Greek
Ν&Nu;&#925;&#x39D;Greek
Ξ&Xi;&#926;&#x39E;Greek
Ο&Omicron;&#927;&#x39F;Greek
Π&Pi;&#928;&#x3A0;Greek
Ρ&Rho;&#929;&#x3A1;Greek
Σ&Sigma;&#931;&#x3A3;Greek
Τ&Tau;&#932;&#x3A4;Greek
Υ&Upsilon;&#933;&#x3A5;Greek
Φ&Phi;&#934;&#x3A6;Greek
Χ&Chi;&#935;&#x3A7;Greek
Ψ&Psi;&#936;&#x3A8;Greek
Ω&Omega;&#937;&#x3A9;Greek
&spades;&#9824;&#x2660;Emoji
&clubs;&#9827;&#x2663;Emoji
&hearts;&#9829;&#x2665;Emoji
&diams;&#9830;&#x2666;Emoji
&#9833;&#9833;&#x2669;Emoji
&#9834;&#9834;&#x266A;Emoji
&#9835;&#9835;&#x266B;Emoji
&#9728;&#9728;&#x2600;Emoji
&#9729;&#9729;&#x2601;Emoji
&#9730;&#9730;&#x2602;Emoji
&#9733;&#9733;&#x2605;Emoji
&#9734;&#9734;&#x2606;Emoji
&#9742;&#9742;&#x260E;Emoji
&#10003;&#10003;&#x2713;Emoji
&#10007;&#10007;&#x2717;Emoji
&#9992;&#9992;&#x2708;Emoji
&#9993;&#9993;&#x2709;Emoji
&#9998;&#9998;&#x270E;Emoji
&#10047;&#10047;&#x273F;Emoji
&#10084;&#10084;&#x2764;Emoji
&#9889;&#9889;&#x26A1;Emoji
&#9888;&#9888;&#x26A0;Emoji
&#9881;&#9881;&#x2699;Emoji
&#9749;&#9749;&#x2615;Emoji
&#9851;&#9851;&#x267B;Emoji
Code Snippets
// Encode HTML entities
function encodeHTML(str) {
  return str
    .replace(/&/g, '&amp;')
    .replace(/</g, '&lt;')
    .replace(/>/g, '&gt;')
    .replace(/"/g, '&quot;')
    .replace(/'/g, '&#39;');
}

// Decode HTML entities (safe, using DOMParser)
function decodeHTML(str) {
  const doc = new DOMParser()
    .parseFromString(`<!doctype html><body>${str}`, 'text/html');
  return doc.body.textContent ?? str;
}

What Are HTML Entities?

HTML entities are special codes used to represent characters that have special meaning in HTML, or characters that cannot be easily typed on a keyboard. For example, the less-than sign ("<") is written as &lt; to prevent the browser from interpreting it as the start of an HTML tag. Entities can be written in three formats: named (&amp;), decimal (&#38;), or hexadecimal (&#x26;).

Why Encode HTML Entities?

XSS Prevention

Encoding user input prevents Cross-Site Scripting (XSS) attacks. Without encoding, attackers can inject malicious scripts through form fields, URL parameters, and other user-controlled inputs.

Display Special Characters

Characters like <, >, and & have special meaning in HTML. Encoding ensures they display as text rather than being interpreted as HTML markup by the browser.

Unicode & Special Symbols

HTML entities provide a reliable way to include mathematical symbols (∑, ∞), arrows (→, ⇒), currency signs (€, £), and other special characters across all browsers and encodings.

Email & Legacy Compatibility

HTML email clients and older systems may not support UTF-8 properly. Using HTML entities ensures characters render correctly everywhere, regardless of the character encoding.

Frequently Asked Questions

Is this tool secure? Is my data sent to a server?

All encoding and decoding happens entirely in your browser. No data is sent to any server. The tool uses the browser's native DOMParser API for safe decoding.

What is the difference between named, decimal, and hex entities?

Named entities use human-readable names (e.g., &amp;amp; for &), decimal entities use the Unicode code point in base 10 (e.g., &#38;), and hex entities use base 16 (e.g., &#x26;). All three represent the same character — named entities are most readable, while decimal/hex work for any Unicode character.

When should I use minimal vs standard vs full encoding?

Minimal encodes only the 5 characters that break HTML syntax (<, >, &, ", '). Standard also covers common special symbols. Full encodes all non-ASCII characters — useful for maximum compatibility with legacy systems or email clients.

How does HTML entity encoding prevent XSS?

By converting characters like < and > to &lt; and &gt;, the browser displays them as text rather than interpreting them as HTML tags. This prevents injected <script> tags and event handlers from executing.

Should I use innerHTML or textContent in JavaScript?

Always use textContent (or innerText) when inserting user-provided content. innerHTML parses the string as HTML, which can execute injected scripts. textContent treats everything as plain text, making it safe from XSS.