HTML Entity Encoder & Decoder — Free

Encode special characters to HTML entities or decode entities back to text. Common entities reference included. Free online tool.

Common Entities
<&lt;
>&gt;
&&amp;
"&quot;
'&#39;
(space)&nbsp;
©&copy;
®&reg;
&trade;

HTML Entity Encoder & Decoder — Encode Special Characters

Encode special characters to HTML entities or decode entities back to readable text. Properly encoding characters like <, >, &, and quotes prevents XSS vulnerabilities and ensures your HTML renders correctly. Essential for web developers handling user-generated content.

HTML entity encoding replaces reserved characters with their entity equivalents: < becomes &lt;, >becomes &gt;, & becomes &amp;, and "becomes &quot;. The encoder supports both named entities (like &amp;) and numeric entities (like &#38;). Decoding reverses this process, converting entities back to their character form.

Web developers encode user input before inserting it into HTML to prevent XSS attacks. Content managers encode special characters in CMS content. Email developers encode characters for HTML email compatibility. Technical writers encode code examples for documentation and blog posts.

Always encode the five critical characters: &, <, >, ", and '. Modern frameworks like React and Angular auto-encode output by default, but raw HTML insertion (innerHTML, dangerouslySetInnerHTML) bypasses this protection. When in doubt, encode everything — browsers decode entities automatically during rendering.

While server-side frameworks handle encoding automatically in most cases, this tool is invaluable for manual encoding in static HTML, email templates, and documentation. For generating safe HTML meta tags, see our Meta Tag Generator. For URL encoding (percent-encoding), a URL encoder handles that different encoding scheme.

How the HTML Entity Encoder Works

  1. Paste your text or HTML into the input field
  2. Choose Encode to convert special characters to HTML entities, or Decode to reverse it
  3. Characters like <, >, &, and " are converted to &lt;, &gt;, &amp;, and &quot;
  4. Copy the result for safe use in your HTML documents

Why HTML Entity Encoding Matters

HTML entity encoding converts special characters into their safe HTML equivalents. This is critical for preventing XSS (cross-site scripting) attacks — unencoded user input can be interpreted as executable HTML or JavaScript. Always encode user-generated content before inserting it into HTML. The five characters that must always be encoded are: & (&amp;), < (&lt;), > (&gt;), " (&quot;), and ' (&#39;).

When to Use the HTML Entity Encoder

Use this tool whenever you need to safely display special characters in HTML, or when you encounter encoded entities that need to be converted back to readable text. It is critical for preventing XSS attacks when inserting user-generated content into HTML, encoding code examples for blog posts, and preparing text for HTML email templates.

Common Use Cases

  • Encoding user input before inserting it into HTML to prevent XSS (cross-site scripting) attacks
  • Preparing code snippets with angle brackets and ampersands for blog posts and documentation
  • Encoding special characters for HTML email templates that need to render correctly across email clients Meta Tag Generator — SEO Tags in Seconds
  • Decoding HTML entities in scraped web content to extract clean readable text

Expert Tips

  • When in doubt, encode everything — browsers decode entities automatically during rendering, so over-encoding is safe
  • For code blocks in HTML, encode both < and > to prevent the browser from interpreting tags: use &lt;div&gt; instead of <div>
  • URL encoding (percent-encoding) is different from HTML entity encoding — use the right encoding for the right context

Frequently Asked Questions

Which characters must be encoded in HTML?
Five characters must always be encoded: & (ampersand → &amp;), < (less than → &lt;), > (greater than → &gt;), " (double quote → &quot;), and ' (single quote → &#39; or &apos;). These characters have special meaning in HTML and will break rendering or create security vulnerabilities if left unencoded.
What is the difference between named and numeric entities?
Named entities use readable names like &amp; and &lt;. Numeric entities use code points like &#38; (decimal) or &#x26; (hexadecimal). Both produce the same result. Named entities are more readable; numeric entities cover all Unicode characters including those without named entities.
Do modern frameworks handle encoding automatically?
Yes, frameworks like React, Angular, and Vue automatically encode output by default. However, using raw HTML insertion methods (innerHTML, dangerouslySetInnerHTML, v-html) bypasses this protection. Always be careful with these escape hatches and manually encode any user input.

Related Tools

Learn More