Skip to main content
AllDevToolsHub
📄

HTML Entity Converter

100% Local

Encode and decode HTML entities and special characters.

HTML Entity Converter

Content Sanitization

Escapes characters like <, >, and & for use in HTML content.

Try:
This tool runs entirely in your browser. Your input is never uploaded, logged, or sent to AllDevToolsHub or anyone else, and it keeps working offline once the page has loaded.

Type text to encode special characters as HTML entities, or paste entities to decode back.

Overview

What is HTML Entity Converter?

Convert special characters to HTML entity equivalents (e.g., & to &amp;) and back. Essential for displaying content correctly and avoiding XSS vulnerabilities.
FAQ

Frequently Asked Questions

Reference

Technical Deep Dive

ENCODERS & DECODERS

HTML Entity Converter

Convert special characters to their HTML entity equivalents (e.g., & into &amp;) and vice-versa. Essential for web developers ensuring content displays correctly in HTML documents and avoiding XSS vulnerabilities.

🧬

Spec-Compliant

Follows the RFC or de-facto encoding rules, no custom dialects, no surprises.

🔄

Lossless Round-Trip

Encode then decode and you get back exactly what you put in, byte for byte.

📡

Handles Edge Cases

Unicode, padding, invalid input, surfaced clearly instead of silently mangling output.

01 Critical Escaping Matrix

Literal Entity Code Numeric Code Required Context
<&lt;&#60;HTML Body & Attribute
>&gt;&#62;HTML Body & Attribute
&&amp;&#38;Global (All Contexts)
"&quot;&#34;Attribute Values
'&apos;&#39;Attribute Values

02 Entity Transformation Flow

1
Lexical Scanning The input buffer is scanned for reserved HTML delimiters and non-ASCII Unicode code points.
2
Mnemonic Mapping Identified characters are replaced with their corresponding named entities or numeric references from the HTML5 spec.
3
Buffer Serialization The transformed tokens are re-joined into a sanitized string buffer for secure presentation or data export.

03 When You Reach for HTML Entities

Entity encoding is the boundary between "this is text" and "this is HTML markup." Get it wrong and either the page breaks visually or, much worse, a stored XSS slips through to your users.

  • 🛡️
    Sanitizing user-generated content A comment field that allows raw <script> tags is a stored-XSS factory. Escaping the four critical characters (< > & ") at output time is the OWASP-recommended baseline. Frameworks like React and Vue do this for you on string interpolation.
  • 📄
    Embedding code samples in <pre> / <code> Docs that render literal HTML examples need to escape < and > even inside <pre>. The browser still parses tags there, <pre> only preserves whitespace, not HTML semantics.
  • ✉️
    HTML email templates Marketing footers with &copy; 2026, currency strings like &euro;9.99, and non-breaking spaces (&nbsp;) all rely on named entities. Many email clients still trip over raw UTF-8, so entity references remain the safe path.
  • ⚠️
    URLs embedded in HTML attributes An href containing a URL with & separators must encode each & as &amp;, otherwise the HTML parser eats the next parameter. This is double work because the URL itself is already percent-encoded.
  • 🚫
    Sanitizing content for a JavaScript string literal HTML entities do nothing inside a <script> block, the JS parser ignores them. Escape with JSON-encoding or a dedicated JS-string escaper. Mixing the two is a frequent XSS root cause.

04 Worked Examples

EXAMPLE 1 · NEUTRALIZING AN XSS PAYLOAD
Raw user comment:
<script>alert(document.cookie)</script>
After HTML entity encoding:
&lt;script&gt;alert(document.cookie)&lt;/script&gt;

The browser now renders this as literal text rather than executing it. This is the single most important XSS mitigation for content that is not supposed to contain markup.

EXAMPLE 2 · NAMED VS DECIMAL VS HEX
Three equivalent ways to write an ampersand:
named:   &amp;

decimal: &#38;
hex: &#x26;


All render as:

&

Named entities are limited (~250 in HTML5); numeric entities cover every Unicode code point. For non-ASCII text the numeric forms always work, even in ancient email clients that never learned &hellip;.




EXAMPLE 3 · THE DOUBLE-ESCAPE BUG

Original user input:

Tom & Jerry

Encoded once at the API boundary:

Tom &amp; Jerry

Template engine re-escapes it on render:

Tom &amp;amp; Jerry  →  shows as "Tom &amp; Jerry"

If you see &amp;amp; in your output, escaping is happening twice in the pipeline. Pick one layer, usually the template renderer, and make sure the data that reaches it is raw.




05 Related Tools

Escaping is rarely isolated, different contexts in the same page need different escapers. These pair naturally with HTML entities.

You Might Also Need