HTML Entity Encoder & Decoder

Encode text to HTML entities or decode them back. Named, decimal and hex output, four encoding levels, XSS warnings. Free and runs in your browser.

By

Advertisement

HTML Entity Encoder and Decoder

This HTML entity encoder converts text into HTML entities and converts entities back into plain text, in one place, instantly. Paste a snippet containing <, >, & or quotes and get output that a browser will display as literal characters instead of parsing as markup. Choose named entities, decimal numeric references, hexadecimal references or a mixed strategy, and choose how aggressive the encoding should be. Everything runs in your browser — nothing is uploaded.

The two jobs it does are exact inverses. Encoding takes <div>Hello</div> and yields &lt;div&gt;Hello&lt;/div&gt;, which renders on the page as the tag text rather than creating an element. Decoding takes entity-laden text out of a log line, an XML export or a database column and gives you back the original characters.

Why HTML Entity Encoding Matters

HTML has exactly five characters that carry structural meaning. If untrusted input containing them is written into a page unescaped, the browser cannot tell your markup from the attacker's — that is cross-site scripting in one sentence. Entity encoding removes the ambiguity by replacing each dangerous character with a token that means “display this glyph” rather than “begin a tag”.

The five that always need encoding in an HTML context:

  • & → &amp; (decimal &#38;, hex &#x26;) — encode this one first, or you will double-encode everything that follows
  • < → &lt; (&#60;, &#x3C;)
  • > → &gt; (&#62;, &#x3E;)
  • " → &quot; (&#34;, &#x22;) — essential inside double-quoted attributes
  • ' → &apos; (&#39;, &#x27;) — essential inside single-quoted attributes

Beyond those, a useful reference set of named entities: &nbsp; for a non-breaking space, &copy; ©, &reg; ®, &trade; ™, &euro; €, &pound; £, &yen; ¥, &cent; ¢, &deg; °, &plusmn; ±, &times; ×, &divide; ÷, &frac12; ½, &frac14; ¼, &frac34; ¾, &mdash; —, &ndash; –, &hellip; …, &bull; •, &sect; §, &para; ¶, &dagger; †, &prime; ′, &larr; ←, &rarr; →, &uarr; ↑, &darr; ↓.

Named, Decimal and Hexadecimal Entities

Every character can be written three ways, and the tool lets you pick which:

  • Named — &amp;, &copy;. Readable, but only defined for characters that have a name.
  • Decimal — &#38;. A numeric character reference using the code point in base 10. Works for every Unicode character.
  • Hexadecimal — &#x26;. The same thing in base 16, which is how code points are conventionally written.
  • Mixed — the default: a named entity when one exists, decimal otherwise. This gives readable output without leaving exotic characters unencoded.

All three forms are equivalent to the parser. Numeric references are the safer default when output is consumed by something other than a full HTML parser, because named entities beyond the core five are not universally recognised in XML.

Four Encoding Levels

Encoding more than necessary bloats output and makes diffs unreadable; encoding less than necessary is a vulnerability. The tool offers four levels so you can match the context:

  • Minimal — only the five structural characters. The right default for HTML body and attribute output; it leaves accented letters and emoji intact, which is what you want on a UTF-8 page.
  • Standard — the five, plus control characters and everything outside printable ASCII (code points below 32 or above 126). Use when the output must survive a legacy pipeline that mangles non-ASCII bytes.
  • Extended — the five, plus all non-ASCII characters (above code point 127), leaving printable ASCII punctuation alone.
  • Aggressive — every single character becomes an entity, including letters and spaces. Genuinely useful only for obfuscation demonstrations and for testing whether a parser normalises entities before applying a filter.

Encoding as XSS Defence — and Its Limits

Entity encoding is contextual output encoding, and the context decides whether it works. Inside an HTML element or a quoted attribute value, it is correct and sufficient. Elsewhere it is not:

  • Inside <script> — the HTML parser does not decode entities in a script data block, so entity encoding neither protects you nor round-trips. Serialise to JSON instead.
  • Inside a URL attribute — &#106;avascript: decodes to javascript:, so an entity-encoded payload in href still executes. Validate the scheme, and use percent-encoding via the URL encoder for the query string.
  • Unquoted attributes — encoding quotes does nothing when there are no quotes to break out of; a space is enough to inject a new attribute. Always quote.
  • Inside CSS or an event handler — different escaping rules apply entirely.

The tool flags patterns in your input that suggest an XSS attempt — on* event handler attributes, script and other dangerous tags such as iframe, object, embed and frame, and text that is already heavily entity-encoded (a classic evasion signal). Treat these as review prompts, not as a verdict. And encode on output, never on input: storing pre-encoded data guarantees double-encoding somewhere downstream, which is how &amp;amp; ends up in your page titles. Pair this with a strong Content Security Policy so that a missed escape does not become an executed script.

How to Use the HTML Entity Encoder

  1. Choose Encode or Decode.
  2. Paste your text or markup into the input box.
  3. Pick an entity format — mixed, named, decimal or hex.
  4. Pick an encoding level — minimal for normal web output, higher when a downstream system demands it.
  5. Read the output and the statistics panel, which counts total entities produced and breaks them down by named, decimal and hex.
  6. Review any security warnings, then copy the result.

Decoding accepts all three forms in the same input, so mixed text such as &lt;p&gt;caf&#233; &#x26; bar&lt;/p&gt; comes back intact.

Frequently Asked Questions

What is HTML entity encoding?+

It is the replacement of characters that have structural meaning in HTML — or that are hard to type — with escape sequences the browser renders as the literal glyph. < becomes &lt;, so the browser displays a less-than sign instead of starting a tag.

Is this HTML encoder free?+

Yes. Free, no account, no length limit, and it runs entirely in your browser.

Which characters must I encode?+

At minimum &, <, >, " and '. Encode the ampersand first so you do not re-encode the entities you have just created.

What is the difference between named and numeric entities?+

Named entities like &copy; are readable but exist only for a defined list of characters. Numeric references — decimal &#169; or hex &#xA9; — work for any Unicode code point. Browsers treat all three identically.

Does entity encoding stop XSS?+

In HTML element and quoted-attribute contexts, yes. It does not protect JavaScript contexts, URL attributes such as href and src, CSS, or unquoted attributes — each needs its own escaping rules.

Should I encode data before storing it in my database?+

No. Store the raw value and encode at the point of output, using the encoding appropriate to that context. Encoding on input causes double-encoding and breaks searching, sorting and reuse in non-HTML contexts.

Why do I see &amp;amp; in my output?+

That is double encoding: an already-encoded string was encoded again. Decode it here until it stops changing, then fix the pipeline so encoding happens exactly once, at output.

Do I need to encode accented characters and emoji?+

Not on a UTF-8 page — they display correctly as-is, so minimal encoding is the right choice. Use extended or standard level only when output passes through a system that cannot handle non-ASCII bytes.

Can it decode all three entity formats at once?+

Yes. The decoder handles named entities, decimal references and hexadecimal references in the same input, in any combination.

Is my input sent to a server?+

No. Encoding, decoding and the security checks all run locally in your browser. Nothing is transmitted or stored.

This tool is provided for informational and educational purposes only. While we strive for accuracy, we make no warranties about the completeness or reliability of results.