HTML Entities

Encode <, >, & and quotes for HTML, or decode entities back to characters.

Text that has to survive inside HTML

If a string can contain < or & and you drop it into HTML, the browser will treat it as markup. Encoding turns those characters into entities. Decoding turns entities back into characters when you are reading source. This is not the same as JSON escape, and it does not remove tags the way the HTML-strip tools do. It rewrites characters.

How to use it

  1. Paste the text or the entity string.
  2. Choose Encode or Decode. Encode always escapes &, <, > and both kinds of quotes.
  3. Leave “Also encode characters outside ASCII” on when you want 中文 and accents as &#xHHHH;. Turn it off when the page is UTF-8 and only the markup characters must change.
  4. Decode accepts decimal entities such as &#20013;, hex entities such as &#x4E2D;, and a short list of names: amp, lt, gt, quot, apos, nbsp, copy, reg, trade, mdash, ndash, hellip, laquo, raquo, bull, middot, euro, pound, yen, cent, sect, para, deg, plusmn, times, divide, micro. A name that is not in that list is left unchanged.

What you should expect

Encode does not wrap the result in a tag and does not add a doctype. A bare & that is already the start of an entity will be escaped again if you encode twice, so &amp; appears. Decode once to undo one layer. Named entities outside the list above, including many HTML5 names, stay as you pasted them. Numeric entities that are not a valid code point stay as text.

Where people use it

  • Putting a user string into HTML without letting it become a tag.
  • Reading a feed or an old page where Chinese was stored as numeric entities.
  • Checking what a template will show before you render it.

Questions

Why did &euro; stay as text?

If you encoded, the ampersand itself was escaped, so you see the entity source. Switch to Decode to turn a known name into the character.

I needed every HTML5 name.

This page covers the names people hit in ordinary text, plus any numeric entity. An unknown name is kept so a typo is visible instead of being dropped.