HTML Formatter

Pretty-print HTML with real indentation, or minify it safely

Runs in your browserUtility01Formatters & Validators

What is HTML Formatter?

An HTML formatter re-indents markup by tag nesting so the structure is obvious at a glance. Minify mode collapses the whitespace between tags and removes comments, while leaving the contents of pre, textarea, script, and style exactly as they were. Everything runs locally in your browser.

How to use HTML Formatter

  1. 1Paste an HTML fragment or a full page.
  2. 2Choose format or minify; formatting lets you pick 2- or 4-space indentation.
  3. 3After minifying, the footer shows how many characters you saved.

Common errors and how to fix them

SymptomCauseFix
The layout shifts after minifyingWhitespace between inline elements is significant, because the browser renders it as a single space.Control the spacing with CSS instead of relying on source whitespace, or skip minification for that fragment.

Frequently asked questions

Does minifying break the indentation inside pre?+

No. The contents of pre, textarea, script, and style are masked out before minification and restored afterwards, so whitespace and line breaks inside those regions survive untouched.

Will formatting fix unclosed tags?+

The formatter interprets your markup using HTML error-recovery rules, so the output may differ from what you expected, but it is not a validator. To find unclosed tags, use an HTML validator or the Elements panel in your browser devtools.

Related tools

All tools