The transform, in order
What the strip HTML operation actually executes
Four substitutions applied in sequence, and the sequence is load-bearing. Script blocks are removed with their contents. Style blocks are removed with their contents. Every remaining tag is deleted wherever it appears, opening or closing, and nothing is put in its place. Then four entities are decoded.
Publishing the order is not decoration. Two of the behaviours on this page follow from it and from nothing else, and a reader who knows the order can predict the output of any input without running it. That is the property a deterministic tool should offer and most pages on this term do not.
- Pass 1
- Script elements, opening tag through closing tag, contents included. Nothing of the JavaScript reaches the output.
- Pass 2
- Style elements, treated identically. CSS does not survive.
- Pass 3
- Any remaining angle-bracketed construct is deleted and replaced with nothing at all. Text between tags is untouched, and so is whitespace outside them.
- Pass 4
- Exactly four entities decoded: non-breaking space to a space, then ampersand, less-than and greater-than to their characters.