HTML Entity Encoder / Decoder

Escape special characters to safely display HTML, or decode HTML entities back to text.

Why Encode HTML Entities?

Encoding HTML (also known as escaping HTML) converts characters like <, >, and & into their corresponding HTML entities (&lt;, &gt;, &amp;). This is necessary when you want to display HTML code snippets on a webpage without the browser interpreting them as actual code, and it is a fundamental practice for preventing Cross-Site Scripting (XSS) attacks.

Common HTML Entities Reference

Here are the most frequently used HTML character entities:

CharacterEntity NameEntity NumberDescription
&&amp;&#38;Ampersand
<&lt;&#60;Less than
>&gt;&#62;Greater than
"&quot;&#34;Double quote
'&apos;&#39;Single quote
©&copy;&#169;Copyright
®&reg;&#174;Registered trademark
&trade;&#8482;Trademark
&euro;&#8364;Euro sign
&nbsp;&#160;Non-breaking space

HTML Encoding and XSS Prevention

Cross-Site Scripting (XSS) is one of the most common web security vulnerabilities. It occurs when an attacker injects malicious scripts into a webpage that other users view. The primary defense is to always encode HTML entities before inserting any user-supplied data into a web page. For example, if a user enters <script>alert('XSS')</script> in a form, it must be encoded to &lt;script&gt;alert('XSS')&lt;/script&gt; before being displayed.