HTML Formatter
Pretty-print HTML with real indentation, or minify it safely
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
- 1Paste an HTML fragment or a full page.
- 2Choose format or minify; formatting lets you pick 2- or 4-space indentation.
- 3After minifying, the footer shows how many characters you saved.
Common errors and how to fix them
| Symptom | Cause | Fix |
|---|---|---|
| The layout shifts after minifying | Whitespace 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 toolsJSON Formatter
Format, minify, and validate JSON with line-and-column error reporting
JSON Validator
Validate JSON syntax and pinpoint the failing line and column
JSON Viewer
Explore JSON as a collapsible tree and read off access paths
JSON Escape / Unescape
Escape and unescape JSON strings
SQL Formatter
Beautify SQL per dialect, including MySQL and PostgreSQL
XML Formatter
Pretty-print or minify XML while checking that every tag is closed