How it works
Your markup is parsed with the browser’s own HTML parser — the same one
that renders every web page — then walked and re-printed with two-space
indentation per level of nesting. Void elements like <img> and <br>
are printed without a closing tag, matching how HTML defines them.
Why formatting can change the structure
Because a real HTML parser is doing the reading, markup with unclosed tags or elements in invalid positions gets corrected the same way a browser would fix it before rendering — so the formatted output reflects the structure a browser actually sees, which can differ from what was typed.
Common uses
Making minified HTML from a build tool readable again, or cleaning up markup copied from a source that stripped all the whitespace.