HTML Formatter & Beautifier
Re-indent HTML, keep pre and textarea byte-exact, and flag unbalanced tags.
About HTML Formatter & Beautifier
Whitespace is not always cosmetic in HTML: inside pre and textarea every space and newline is exactly what the browser paints, so a formatter that blindly re-indents them changes how the page looks. In the other direction, li, td and p have optional end tags in the standard, so a list written without a single closing li is perfectly valid, and a naive indenter that just counts angle brackets turns it into nonsense nesting. This tool builds a real document tree instead of counting characters.
How to use HTML Formatter & Beautifier
- 1
Paste your HTML into the input box; formatting runs as you type.
- 2
Pick the indent: 2, 3, 4 or 8 spaces, or a tab.
- 3
Turn on the long-opening-tag option to give each attribute its own line.
- 4
Read the counters below for output lines, element count and maximum nesting depth, and check any structure warnings with their line numbers.
- 5
Copy the result with the copy button.
Frequently asked questions
Why was the content of my pre block left un-indented?
On purpose. Whitespace inside pre and textarea is significant and rendered literally, so re-indenting it would visibly change the page. Those two elements are copied through byte for byte. Script and style bodies are different: they get re-indented when that option is on, unless they contain a backtick template literal, in which case the tool leaves them alone.
Why does the tool never add a closing tag for br or img?
They are void elements. area, base, br, col, embed, hr, img, input, link, meta, param, source, track and wbr have no end tag at all, and writing a closing br is invalid HTML. All fourteen are recognised, and if you already write the XHTML-style trailing slash it is preserved rather than stripped.
Does an unbalanced-tag warning always mean my HTML is broken?
No. Elements with optional end tags such as li, td, tr, p, option and dd are never reported as unclosed, because the HTML parser closes them for you. Warnings are raised only for tags that genuinely needed a closing tag, for closing tags with no matching opener, and for tags that overlap instead of nesting.
What are the limits?
Input is capped at 800,000 characters and nesting at 512 levels. It is a formatter, not a full W3C validator: it does not check attribute names or semantic rules, and it does not re-wrap a long run of text inside a paragraph.