Whitespace matters in exactly two places
Indenting HTML is safe almost everywhere, because browsers collapse runs of whitespace into a single space. Almost. Two elements do not play along: <pre> and <textarea> preserve every space and newline you put inside them, so reformatting their contents changes what the user sees.
There is a subtler one. Inline elements separated by a newline in the source render with a space between them — which is why a row of <li> or <span> laid out on separate lines can gain gaps that were not there before.
Formatting before reviewing, minifying before shipping
The two operations are opposites and both have their moment. You format to read and review code — a diff on formatted HTML is meaningful, a diff on one long line is not. You minify to serve it, because every removed byte is bandwidth saved on every visit.
Keep the readable version as your source and let the build produce the compressed one. Never the other way round.
Frequently asked questions
Will formatting break my page?
Not in normal markup. Be careful only with <pre> and <textarea>, whose whitespace is meaningful and displayed as-is.
Does it fix invalid HTML?
No. It indents what you give it. Unclosed tags may indent oddly, which is itself a useful signal that something is wrong.
Is my code sent to a server?
No, everything happens in your browser.