Skip to main content
Developer Tools

HTML Entity Encoder: Encode and Decode HTML Entities

June 2026 · 3 min read

HTML entities are special codes that represent reserved or special characters in HTML. Without them, characters like <, >, and & would break your HTML structure or expose your site to XSS attacks.

The 5 Most Important HTML Entities

&
&amp;

The & symbol starts all HTML entities, so it must always be encoded

<
&lt;

Less-than opens HTML tags — must be encoded in text content

>
&gt;

Greater-than closes HTML tags — encode for safety

"
&quot;

Double quote is used in attribute values — encode inside attr="..."

'
&apos;

Single quote is used in attribute values — encode inside attr='...'

When to Encode HTML Entities

  • In template engines: When outputting user-provided data into HTML (prevents XSS)
  • In email templates: HTML email clients are strict — always encode special characters
  • In attribute values: Any quotes inside attributes need encoding
  • Displaying code: Use &lt; and &gt; to show <html> tags visually
  • Special symbols: Use &copy;, &trade;, &euro; for © ™ € in HTML

When NOT to Encode

Don't encode characters that are inside <script> or <style>tags — those contexts have their own escaping rules. Also don't double-encode already-encoded entities (turning &amp; into &amp;amp;).

Encode or decode HTML entities now

Instant conversion · Reference table included · 100% free

Open HTML Entity Encoder →

Frequently Asked Questions

What are HTML entities?

HTML entities are special codes used to display reserved or special characters in HTML. For example, &amp; displays & (ampersand), &lt; displays < (less-than), and &gt; displays > (greater-than). Without entities, these characters would be interpreted as HTML markup.

Why do I need to encode HTML entities?

You need to encode HTML entities to: (1) display characters that have special meaning in HTML like <, >, and &; (2) prevent XSS (cross-site scripting) attacks when displaying user-provided text; (3) display special symbols like © (&copy;) and ™ (&trade;) correctly across all browsers.

What is the HTML entity for &?

The HTML entity for the ampersand (&) is &amp;. Always encode & as &amp; in HTML text content and attribute values, since & starts all other HTML entities and can confuse parsers if left unencoded.

What is the HTML entity for a space?

A regular space is already valid in HTML. The HTML entity &nbsp; is a non-breaking space — it prevents line breaks between words and ensures the space is always visible (even multiple spaces). Use &nbsp; when you need a space that cannot be broken across lines.

How do I decode HTML entities?

Switch the tool to Decode mode, paste your HTML-encoded text (containing &lt;, &amp;, etc.) and click convert. The tool uses the browser's built-in HTML parser to accurately decode all standard entities back to their original characters.