HTML Entities Encoder

Escape text so it is safe to put in HTML, or decode entities back to readable text. Encoding is done in a single pass over the characters, which sidesteps the classic bug where escaping the angle brackets before the ampersands turns a less-than sign into < — a double-escape that is easy to write and annoying to spot. By default only the five characters HTML actually requires are escaped; you can also escape every non-ASCII character, and choose named entities over numeric ones. Decoding uses an explicit table and direct numeric parsing rather than the common innerHTML trick, because handing markup somebody else wrote to the HTML parser is precisely what you do not want in a tool whose entire job is processing markup somebody else wrote. Unrecognised entities are left alone, so a bare ampersand in ordinary prose survives.

The entities that matter most

CharacterNamedNumeric
&&&
<&lt;&#60;
>&gt;&#62;
"&quot;&#34;
'&apos;&#39;
non-breaking space&nbsp;&#160;
—&mdash;&#8212;

When to use it

  1. Escape user-supplied text before putting it into a template.
  2. Decode entities out of a scraped page or an RSS feed.
  3. Fix text that has been double-escaped somewhere in a pipeline.
  4. Show code samples on a page without them being parsed as markup.
  5. Escape non-ASCII text for a system with an unreliable charset.

How to Use

  1. Choose encode or decode.
  2. Paste your text or your entities.
  3. Adjust the escaping options if you need them, then copy the result.

Features

  1. Single-pass encoding, so no double-escaping
  2. Optional escaping of every non-ASCII character
  3. Named or numeric output
  4. Decodes named, decimal and hexadecimal references
  5. Astral characters such as emoji handled correctly
  6. Unknown entities left untouched, not eaten
  7. Table-based decoding, never innerHTML
  8. 100% client-side

FAQs

Is my text uploaded?

No. Everything runs in your browser.

Which characters actually need escaping?

Ampersand, less-than and greater-than always; double and single quotes when the text goes inside an attribute. That is the default here. Everything else is optional and only matters when the charset cannot be relied on.

Why is my text showing as &amp;lt; somewhere?

It has been escaped twice. Something escaped the less-than into &lt;, then escaped that ampersand again. Decode it twice here to recover the original, and look for two escaping steps in your pipeline.

Are all named entities supported when decoding?

The ones people actually meet — the required five plus punctuation, currency, symbols and arrows. The full HTML5 list runs to a couple of thousand names; anything not in the table is left untouched rather than mangled, and numeric references cover every character regardless.

Why not just use innerHTML to decode?

Because it feeds untrusted markup to the HTML parser, and untrusted markup is exactly what this tool takes as input. A table plus numeric parsing gives the same answer without that.

Does it handle emoji?

Yes. Numeric references above the basic plane decode correctly, so &#127881; becomes a party popper. Lone surrogates are refused, since they are not real characters.

Technical Details

Encoding walks the string one character at a time rather than running a series of replacements, which avoids the ordering trap that catches most hand-written escapers: replace the angle brackets before the ampersands and the ampersands those replacements just introduced get escaped a second time, turning a less-than sign into &amp;lt;. Escaping ampersand first works, but only if you remember, and a single pass makes the question moot. By default only the five characters that are structurally significant in HTML are escaped; an option escapes every non-ASCII character as well, for systems with no dependable charset declaration, and another chooses named entities over numeric ones where a name exists. Decoding is deliberately not done the way most examples on the web suggest, which is to assign the string to an element's innerHTML and read textContent back. That approach hands markup somebody else wrote straight to the HTML parser — and markup somebody else wrote is the exact input this tool exists to process. Instead an explicit table covers the named entities people actually encounter, and numeric references are parsed directly in both decimal and hexadecimal form, including astral characters above the basic plane. Values outside the Unicode range, and lone surrogates, are left as written rather than converted, because neither is a real character and producing one would corrupt the string. Anything unrecognised is returned untouched, so a bare ampersand followed by a word — very common in real text — survives instead of being eaten. Everything runs in your browser.

Developer Tools

Developer Tools

  • Number Base Converter
  • JSON Tree Viewer
  • JSON Flattener
  • JSON Diff Checker
  • JSONPath Extractor
  • JSON Schema Generator
  • License Generator
  • Nanoid Generator