HTML Entity Encoder / Decoder

Paste text to escape characters like <, >, & and quotes into safe HTML entities, or paste encoded text to decode it back. Useful before pasting code into a page. Everything runs in your browser.

Enter text or HTML and press Convert.

Why you escape HTML

Browsers treat certain characters as markup: < starts a tag, & starts an entity, and quotes delimit attributes. To show those characters as literal text — say, a code sample or a stray ampersand in a title — you replace them with HTML entities so the browser prints them instead of interpreting them.

< → &lt;  > → &gt;  & → &amp;  " → &quot;  ' → &#39;

Encoding also helps prevent broken layouts and a class of injection bugs, since user text can no longer be mistaken for tags. Decoding does the reverse, turning entities back into the original characters.

Worked example

The string <b>Tom & Jerry</b> encodes to:

< and > become &lt; / &gt;.
& becomes &amp;.
Result: &lt;b&gt;Tom &amp; Jerry&lt;/b&gt; — shows as text, not bold.

Named vs numeric entities

Named entities like &copy; and &amp; are readable but only exist for specific characters. Numeric entities like &#169; (decimal) or &#xA9; (hex) work for any Unicode code point, which is why the "all non-ASCII" mode uses numeric form — it's universal. For most web use, escaping just the five essentials is enough.

Tip: converting Markdown to a page? Pair this with the Markdown to HTML converter.

The five characters that matter (and why)

For inserting untrusted text into ordinary HTML, escaping just five characters is enough to keep it as text rather than markup:

CharacterEntityWhy it's dangerous unescaped
<&lt;Starts a tag — lets text open <script> or other elements.
>&gt;Closes a tag; escaping it avoids edge-case parsing surprises.
&&amp;Starts an entity; without escaping, &copy; in user text turns into ©.
"&quot;Ends a double-quoted attribute value, letting text break out of it.
'&#39;Ends a single-quoted attribute value (use &#39;&apos; isn't valid in HTML 4).

Escaping depends on context — this is the part that bites people

HTML entity encoding is correct for one place: text and attribute values inside an HTML document. It is not the right escaping everywhere, and using the wrong one is how cross-site scripting (XSS) bugs happen:

  • Inside HTML text or an attribute → HTML-entity encode (what this tool does). ✅
  • Inside a <script> block or a JS string → you need JavaScript string escaping, not HTML entities. &lt; inside a script is just the literal characters, not a <.
  • Inside a URL or query parameter → use percent-encoding via the URL encoder, not HTML entities.
  • Inside a CSS value or an on* event handler → these have their own escaping rules and are best avoided for untrusted data entirely.
Important: this tool is for displaying or generating snippets, not for securing a production app. In real code, never build HTML by string-concatenating user input. Use your framework's templating (React, Vue, Angular and others auto-escape HTML text by default) or a vetted library, which applies the correct escaping for each context. Manual escaping is error-prone precisely because the right rule changes with where the value lands.

Frequently asked questions

Which characters must I always escape?

The five essentials are < > & " and '. Escaping these is enough to safely place arbitrary text inside HTML content and attributes without breaking the markup.

What's the difference between named and numeric entities?

Named entities like &copy; are human-readable but exist only for certain characters. Numeric entities like &#169; work for any Unicode character, so they're the universal fallback.

Can it decode entities back to text?

Yes. Switch the direction to 'Decode' and paste encoded text; the tool turns named and numeric entities back into the original characters using the browser's own parser.

Is anything uploaded?

No. Encoding and decoding run in your browser. Nothing you paste is sent to a server, so it's fine for private or unpublished content.

MB
Mustafa Bilgic · Editor, Calcool
Encodes the five HTML-significant characters plus optional numeric entities for non-ASCII; decoding uses the browser's native HTML parser. Everything runs in your browser — nothing you enter is uploaded, logged or stored.

Related calculators