Skip to main content

HTML Entity Encoder / Decoder

Encode and decode HTML entities for safe text in attributes and templates.

About this tool

HTML Entity Encoder / Decoder converts between raw text (with <, >, &, ", ') and the entity-escaped forms. Useful when you need to drop user-supplied text into an HTML attribute, write a code sample into a blog post, or decode something you’ve been given.

What we encode

  • &&amp;
  • <&lt;
  • >&gt;
  • "&quot;
  • '&#39; (apostrophe)

Numeric entities (&#x2F;) are produced when characters don’t have a named entity. Common ones like &rsquo; are not substituted — we keep the numeric form to avoid hidden rewrites.

How decoding works

Decoding uses the browser’s own HTML parser via a hidden <textarea> innerHTML round-trip. This means numeric refs, named refs (e.g. &copy;), and the malformed trailing-semicolon variations all resolve correctly.

Limitations

  • Decoding won’t actually parse HTML — it converts entity references to characters. If your input is something like &lt;script&gt; you get back <script>, not a script that runs.
  • If you have malformed numeric entities (e.g. &#xZZ;), the browser will swallow them silently. Check your result.

Use cases

  • Encoding a value that will land inside an HTML attribute value or a <textarea>.
  • Decoding an old email-archive excerpt to extract the original characters.
  • Cleaning copy-pasted HTML that has entities you don’t want.

Privacy

Pure string transformation, runs in your browser.