Skip to content
Developer

HTML entity encoder and decoder

Turn an HTML snippet into text you can display in a page, or make common entities such as & and < readable again. The result is shown as text for you to inspect and copy.

Runs in your browser — your input is not uploaded to ToolsNow.

Plain text
0 chars0 words0 lines
Encoded HTML
0 chars0 words0 lines

How to use

  1. Choose Encode or Decode. Encode escapes markup characters. Decode turns supported named and numeric entities back into characters.
  2. Paste the text. For example, encoding <b>Hello</b> gives &lt;b&gt;Hello&lt;/b&gt;.
  3. Copy for the right destination. Use the encoded result in an HTML text context. Check if your template or CMS already escapes text, since escaping it again can leave entity names visible.

Questions

Which characters are encoded?

The encoder replaces &, <, >, double quotes and single quotes with &amp;, &lt;, &gt;, &quot; and &#39;. It does not convert every non-ASCII character into an entity.

Why did &copy; stay unchanged?

The decoder supports six named entities: &amp;, &lt;, &gt;, &quot;, &apos; and &nbsp;. Other named entities are left as written. Decimal and hexadecimal numeric forms work for valid Unicode code points: &#65; and &#x41; both become A. Include the semicolon.

Does this sanitise HTML or prevent XSS?

No. Escaping text for an HTML text node is different from sanitising markup or preparing data for a URL, script or style block. Use context-aware escaping in your application. Decoding untrusted entities and then inserting the result as HTML can reintroduce markup.

Why does a decoded &nbsp; still behave differently from a space?

It becomes a non-breaking space, U+00A0, rather than an ordinary space. It looks similar but prevents wrapping at that point. Decoding the entity does not remove that behaviour.

Published by ToolsNow. How tools and sources are checked · Report a problem

Related tools