Developer Encoding

HTML encoder

What to do

Processed in your browser · nothing is uploaded

Local · escaping is not sanitising
Advertisement
320 × 100

Escapes the five characters that must be escaped in HTML; `&`, `<`, `>`, `"` and `'`, and decodes named, decimal and hexadecimal entities back again.

How to use the html encoder

1 Type or paste the text.
2 Encode escapes the five characters in a single pass over the string.
3 Encode non-ASCII too adds numeric entities above 127; only useful for a legacy encoding.
4 Decode turns entities back into the characters they stand for.

Order is the classic bug. Escape < to &lt; first and then escape ampersands, and you have &amp;lt;, which the page displays as literal text. Encoding here is a single pass over all five characters, so it cannot happen inside the tool, but it happens constantly in pipelines, where a template escapes a value some framework had already escaped. If you are seeing &amp;lt;, find the second escape rather than decoding twice for ever.

The quote is written &#39; rather than &apos; on purpose. &apos; is defined in XML and in HTML5 but was never part of HTML 4.01, so the numeric form is the one every parser understands. Quotes only strictly need escaping inside an attribute value; escaping them in text content is harmless and simpler than deciding each time.

Escaping everything above ASCII as numeric entities is a separate option and mostly historical. It was necessary when pages were served as Latin-1; with UTF-8 it only makes the file larger and harder to read.

Two limits worth stating. Escaping is not sanitising: it makes text display safely, and it does not make user-supplied markup safe to insert, which needs an allowlist-based sanitiser. And the decoder handles numeric entities in full, decimal and hexadecimal, plus the common named ones: a rarer named entity is left exactly as it is rather than guessed at.

Questions

Ampersand, less-than and greater-than always; double and single quotes inside attribute values.

WHATWG, named character references
Advertisement
300 × 250
Was this tool any good?
Internal signal only · I use it to find the tools worth rebuilding