How to Use This Tool
Paste text to make it safe to drop into HTML, or paste HTML to see the plain characters back. The
counters underneath show whether the input was already encoded — the usual reason a page displays
& to a reader.
Only five characters matter
Despite the size of the entity tables floating around, the working list is short:
&→&— always, because it starts every entity.<→<— because it starts a tag.>→>— not strictly required in text, and cheap insurance."→"— needed inside a double-quoted attribute.'→'— needed inside a single-quoted attribute.
Escape all five everywhere and you never have to think about which context you are in. It costs a few bytes and removes an entire category of bug.
The ampersand goes first
Encoding by hand fails in one predictable way. Replace < with <
first, then replace & with &, and the second pass mangles what the
first produced: < becomes &lt;, and the page displays
< to the reader instead of a less-than sign.
The ampersand must be replaced before anything that introduces one. Decoding runs the opposite way
— resolve & last, or you turn &lt; into a working tag,
which is a real security bug rather than a cosmetic one.
Entities are not for accented letters
Writing é for é or 中 for 中 is a habit
from the days of single-byte encodings. Modern pages are UTF-8, and accented letters, CJK characters and
emoji are all perfectly legal typed directly.
Encoding them anyway makes the file bigger, the source unreadable, and the text harder to search
— é does not match a search for é. The "everything" option exists
because you will occasionally meet a legacy system that needs it, not because it is a good default.
Escaping is not the same as sanitising
Escaping turns text into text: after it, <script> displays as characters and does
nothing. That is the right answer when the content should never be markup.
If the content is meant to contain markup — a rich-text editor, user-submitted HTML — escaping is the wrong tool, because it would show the tags rather than apply them. That needs a sanitiser with an allowlist of permitted elements and attributes, which is a much harder problem and not one to solve with string replacement.
