About HTML Formatter
The HTML formatter indents markup so its nesting is visible, putting each element on its own line and stepping children in by depth. It is the same idea as the XML formatter, applied to HTML — useful the moment you are handed a template that arrived as a single unbroken line.
One practical detail to know: the formatting operates on the document body. That matches how HTML is usually worked on, since the body is where the markup you are editing lives, but it means a complete document with a head section will not have that head reproduced in the output.
As with any markup formatter, the result is for reading rather than for serving. Whitespace between block elements is insignificant, but whitespace inside inline elements is not — reformatting around a run of inline text can introduce visible spacing in a browser.
How to use HTML Formatter
- 1 Paste the HTML markup to format.
- 2 Elements are placed on separate lines and indented by nesting depth.
- 3 Copy the result for code review, documentation, or debugging a template.
Frequently asked questions
Does this work on a full HTML document including the head?
The formatting applies to the document body. A complete page will render its body markup correctly indented, but the head section is not reproduced in the output — paste just the markup you need to inspect if that matters.
Can reformatting change how my page looks?
It can, if it introduces whitespace inside inline elements. Whitespace between block-level elements is insignificant, but a newline inserted between two words inside a paragraph or a link becomes a visible space. Keep formatted output for reading rather than serving it directly.
How is this different from the XML formatter?
HTML is parsed with the browser's HTML rules rather than as strict XML, which matters for documents containing unclosed tags or void elements such as <br> and <img>. Those are handled per the HTML specification here, whereas an XML parser would reject them.
Will it fix invalid or unclosed tags?
The HTML parser corrects certain structural problems as it builds the tree, because that is what HTML parsers do by design. It is not a validator, though — if you need to find unclosed tags, use a dedicated HTML validator rather than inferring them from formatted output.
Free, online, and private
Free to use
HTML Formatter is completely free. There is no account to create, no login, and no hidden charge or usage limit.
Runs online in your browser
It is a free online tool that runs entirely in your browser. Nothing to download or install — open the page and start using it right away.
Your data stays private
All processing happens locally on your device. Your input is never uploaded, stored, or tracked, so it never leaves your browser.
How HTML Formatter behaves in detail
These are the specifics of this implementation — the exact ranges, defaults and fixed settings you are working with.
| Parameter | Value |
|---|---|
| Parser | DOMParser with the text/html mime type — a real HTML parser, not a regex pass |
| Input scope | only the parsed document's <body> element is serialized; the <head>, <title> and doctype are dropped |
| Reformatting step | a newline is inserted wherever a `>` is immediately followed by `<` — that is the only edit |
| Indent | none — no space or tab is inserted at any depth |
| Normalisation | tag case, attribute quoting and closing-tag style come from the serializer, not from the input |
Compiled from the implementation of this tool and checked against it by itoolnet.
What HTML Formatter does not do
Knowing the edges of a tool saves more time than another list of its features. These are the cases where it will not do what you might expect.
- Nothing is indented. Since the only formatting is a break between adjacent tags, a deeply nested fragment comes back with every element starting at the left margin and no visual hierarchy at all.
- Everything outside the body is discarded. A complete page is accepted, but only the body markup is returned, so any <title>, <meta> or head-level <script> is not part of the result.
- A real HTML parser runs first, so the markup is silently repaired instead of reported: unclosed tags are closed, tag names are lowercased and attribute quoting is normalised, and the output is not a re-print of what you typed.
- A break is only inserted when the input has no character at all between two tags. A source written as "</div> <div>" is left as it was, so the output can mix formatted and unformatted runs.
Tested and documented by itoolnet, the team that builds and maintains this site.