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.
| Character | Named | Numeric |
|---|---|---|
| & | & | & |
| < | < | < |
| > | > | > |
| " | " | " |
| ' | ' | ' |
| non-breaking space | |   |
| — | — | — |
No. Everything runs in your browser.
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.
It has been escaped twice. Something escaped the less-than into <, then escaped that ampersand again. Decode it twice here to recover the original, and look for two escaping steps in your pipeline.
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.
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.
Yes. Numeric references above the basic plane decode correctly, so 🎉 becomes a party popper. Lone surrogates are refused, since they are not real characters.
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 &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.