LocalToolkit
HomeEncoding & Decoding › HTML Entity Encoder / Decoder

HTML Entity Encoder & Decoder

Turn markup-significant characters into entities, and read them back.

🔒 Runs in your browser. Nothing is uploaded — verify it in the network panel, or disconnect and try again.

The five you must always escape

CharacterNamed entityNumericWhy it matters
&&&Starts every entity — escape it first, or you create phantom entities
<&lt;&#60;Opens a tag
>&gt;&#62;Closes a tag; needed mainly to avoid ]]> sequences
"&quot;&#34;Ends a double-quoted attribute
'&#39; (there is no &apos; in HTML4)&#39;Ends a single-quoted attribute

Escape the ampersand first when writing an encoder, or you will double-escape the entities you just generated: &lt; becomes &amp;lt; and renders as visible text &lt;.

Named versus numeric references

Where entity encoding is genuinely necessary

Entity encoding is context-dependent, not universal. A value inside <script>, inside a CSS url(), or inside an unquoted attribute needs different treatment. The robust pattern is to write the value as data and let a template engine — or textContent in the DOM — do the escaping, rather than filtering the string on the way in.

How to use it

  1. Paste the text or HTML you want to convert.
  2. Encoding produces display-safe entities; decoding turns references back into characters.
  3. Choose whether to escape only the five critical characters or every non-ASCII character too.
  4. Copy the result.

Worth knowing

  • HTML5 defines over 2,000 named character references.
  • Ampersand must be escaped before angle brackets in any encoder.
  • &apos; is undefined in HTML4 but valid in HTML5 and XHTML.
  • Numeric references accept decimal (&#8212;) and hex (&#x2014;) forms.

Limitations

  • Entity-encoding is not sufficient XSS protection — the danger depends on the HTML context.
  • Encoding a whole document would also encode its tags, turning markup into visible source.
  • Some decoders silently drop unknown entities rather than reporting them.
  • JSON is not HTML: inside JSON, < needs no escaping at all.

Frequently asked questions

Is entity encoding enough to prevent XSS?
Only for the specific context of an HTML text node or a quoted attribute. Inside <script>, in a URL, or in a CSS context different escaping applies, and the safest approach is to let a template engine or DOM text node handle it.
What is `&amp;amp;`?
A double-escaped ampersand: it renders as the visible text &amp;. It is the signature of text that has passed through two encoders, one of which escaped the ampersand produced by the other.
What is `&nbsp;`?
A non-breaking space (U+00A0). It prevents a line break between two words, which is what you want in 10 kg or Dr. Smith, and it is a real character rather than ordinary whitespace.
Should I escape non-ASCII characters?
Usually not. UTF-8 handles them directly, and escaping every accented letter hurts readability and file size. It is worth doing only when the output must survive a strictly ASCII-only channel.
Related tools
URL Encoder / DecoderBase64 Encoder / DecoderJSON Formatter & ValidatorXML to JSON ConverterJWT DecoderHex Encoder / Decoder
Keep reading
How browser-only processing worksAll Encoding & Decoding toolsEvery tool on the site