ToolsWhisper
Developer tools

HTML Entity Encoder/Decoder

Escape text for HTML, or decode entities back into plain characters.

  • Runs in your browser
  • Nothing is uploaded
  • Free, no sign-up
Direction
Text or HTML
Result

Only & < > and quotation marks are escaped. This is all that is needed to show text safely inside HTML.

About this tool

Turn the characters that have special meaning in HTML into entities so they display as text, or decode entities back into the characters they stand for. Choose whether only the essential characters are escaped, or every non-ASCII one too.

How to use it

  1. Choose Encode or Decode.
  2. When encoding, pick essential characters only, named, decimal or hexadecimal.
  3. Paste your text and copy the result.

The five characters that matter

Escaping exists because a few characters mean something to an HTML parser:

Character Entity Why it needs escaping
& &amp; Starts every entity, so a bare one can swallow the text after it
< &lt; Starts a tag
> &gt; Ends a tag, so it is escaped for symmetry
" &quot; Ends a double-quoted attribute value
' &#39; Ends a single-quoted attribute value

Essential mode does exactly this and leaves everything else alone. It is all you need to show text safely in a page served as UTF-8.

Escaping is for one context only

Entities are correct for HTML text and attribute values. They are the wrong tool elsewhere:

  • Inside a <script> block, content is not entity-decoded at all, so &lt; would appear literally. Put data there as JSON, with < escaped as \u003c.
  • In a URL, special characters are percent-encoded instead: see the URL encoder.
  • Escaping does not make untrusted HTML safe to insert. It makes text display as text. Letting a user's HTML through needs a sanitiser, not an encoder.

Named, decimal or hexadecimal

Named references such as &eacute; and &copy; are readable in source. HTML 4 defines 252 of them, which is what this tool knows. Characters without a name are left as they are.

Decimal (&#233;) and hexadecimal (&#xE9;) references work for every Unicode character, and a single reference covers an emoji that is two UTF-16 code units in JavaScript.

If your page declares UTF-8, which it should, you rarely need any of them beyond the essentials. Reach for numeric references when the text may be saved or transmitted in an encoding you do not control, such as an email template or a file passed through an older system.

What decoding does and does not do

Decoding replaces references that end in a semicolon with their characters, in a single pass: &amp;lt; becomes &lt;, not <. Anything unrecognised, and bare ampersands like the one in AT&T, are left as written.

Numeric references between 128 and 159 are read the way browsers read them, as Windows-1252 characters, so &#150; is an en dash. Out-of-range or surrogate values become the replacement character.

Frequently asked questions

Why &#39; for an apostrophe and not &apos;?

&apos; is not part of HTML 4 and is not understood by some older parsers and email clients. The numeric form works everywhere.

Does it decode newer entities such as &check; or &rarr;?

It knows the 252 references of HTML 4, which includes &rarr;, &hearts; and &euro;. Names added in HTML5, such as &check;, are left unchanged.

How do I write a non-breaking space?

Use &nbsp;, which is U+00A0. In Named mode a non-breaking space in your text is converted to it, so it stays visible in the source.

Should I escape text before putting it in a database?

No. Store the original text, and escape for the output context when you render it. Storing escaped text leads to double-escaping and makes searching harder.

Related tools