HTML Formatter
Pretty-print messy HTML with clean indentation.
Free HTML pretty-printer. Indent nested tags with 2 or 4 spaces while leaving pre, script, style and textarea content untouched, in your browser.
Loading tool…
If the tool stays on this message, make sure JavaScript is enabled, then reload the page.
About HTML Formatter
Minified HTML arrives as a single unreadable line, fine for browsers, miserable for humans. A formatter re-indents nested tags so the document's structure becomes visible at a glance: parents, children, and siblings each on their own line at their own depth. This tool does that with a choice of 2- or 4-space indentation, entirely in your browser.
It's built to be safe with real-world markup. Content inside pre, script, style, and textarea tags is left byte-for-byte untouched, because whitespace there is significant, reformatting a code sample or a script would change its meaning. Void elements like img and br are handled correctly, and only the whitespace between tags is adjusted, so the formatted page behaves exactly like the original.
Know its limits: this is a formatter, not a validator. Unclosed or misnested tags are indented as-is rather than fixed, so if your markup is broken, run it through a validator first. And keep the workflow straight, format for editing and debugging, then minify again for production. The two are inverses, not competitors.
How to use HTML Formatter
- Paste messy or minified HTML.
- Pick 2- or 4-space indentation and click Format.
- Copy the pretty-printed result.
Why use this tool?
- Readable nested indentation
- Pre, script, style and textarea left untouched
- Void elements handled correctly
Tips for best results
- Debug copied snippets: paste markup from 'view source' to see the nesting structure before editing.
- Choose your indent: 2 spaces for compact diffs, 4 spaces for maximum readability in deep nesting.
- Don't reformat inside pre or script: the tool already protects these, but avoid manual edits there, whitespace is significant.
- Validate broken markup separately: the formatter won't fix unclosed tags, so run a validator if the output looks wrong.
- Minify for production: format while you work, then minify before deploying to keep file sizes small.