HTML Formatter
Format and beautify HTML or minify it. Indent size, comment stripping, and self-closing tag awareness.
Enter input above to see the result.
What is this for?
HTML markup arrives in your editor in all sorts of states — minified for production, generated by templating engines with no regard for whitespace, hand-typed and indented inconsistently. This tool reformats any HTML fragment with consistent indentation per nested element, recognising void elements (<img>, <br>, <meta>) and inline elements (<a>, <span>, <strong>) so the output looks like real HTML, not a layout-by-rule. Minify mode strips inter-tag whitespace and optionally comments. Everything stays in your browser.
When to use it
- Pretty-printing a minified HTML email or a "view source" copy of a page so you can read its structure.
- Cleaning up a snippet from a CMS / WYSIWYG before pasting into a code review.
- Minifying a static HTML asset before deploying — fewer bytes over the wire, no comments leaked.
- Stripping author comments from a template before publishing.
Common gotchas
- This is a pragmatic tokenizer, not a full HTML5 parser. It works well on real-world fragments but won't recover from severely malformed input the way browsers do (browsers run the full HTML parsing algorithm and fix up errors silently — this tool doesn't).
- Whitespace inside
<pre>,<textarea>,<script>,<style>is preserved. These elements are treated as raw and aren't re-indented. - Inline elements stay on the same line as their parent text —
<p>some <b>bold</b> text</p>won't be split across lines. - "Collapse whitespace" changes the rendered output for some content. Two spaces become one. If your design relies on multiple spaces or non-breaking sequences, leave it off.
- Self-closing notation in HTML is cosmetic.
<br/>and<br>are equivalent in HTML5; this tool preserves whatever you wrote. - Minify is not a security boundary. Don't rely on stripping comments to hide secrets — they were already shipped to the client.