HTML Formatter
How the formatter parses
A robust formatter cannot work line by line, because minified HTML has no lines. This one tokenises: it scans for tags, comments, doctypes and text, then rebuilds the document with an indent stack — opening tags push a level, closing tags pop one, and self-contained void elements do neither. Raw-text elements (script, style, pre, textarea) are captured whole and emitted verbatim at the current indent, since reformatting their contents could change what they do. Text nodes are trimmed of their surrounding whitespace and placed on their own line at the current depth, so the tree reads top to bottom like an outline.
The result is not a canonical form — two good formatters can disagree about edge cases like mixed inline content — but it is deterministic, structure-revealing, and safe to re-run: formatting already-formatted output changes nothing, a property worth checking in any such tool.
Reading other people's HTML
The commonest real use of a formatter is not tidying your own code — your editor does that — but making sense of someone else's: the shipped markup of a site you are debugging, an email template exported from a marketing platform, a component copied out of a design system, or the output of a template engine that emits everything on one line. Formatted, the document's actual structure becomes auditable: nesting errors show up as indentation that drifts or fails to return, wrapper divs multiply visibly (the famous div-soup of mature pages, where six nested containers do the work of one), and the difference between what the author intended and what the browser received gets easier to spot. Two habits help: format a copy, never the only copy, and diff before and after if the markup is going back into production, because a formatter's opinion about whitespace is occasionally a rendering change in disguise, as the questions below explain.
Where does this leave the editor question? Use the formatter your team already uses — Prettier, an IDE extension, or this page for one-off work — but use exactly one per codebase, because duelling formatters produce endless diff noise as each rewrites the other's choices. The value of formatting was never the specific indent; it is that structure becomes visible, diffs become reviewable, and arguments about style end. Any consistent formatter delivers all three, which is why the choice matters less than the consistency.
And if the document fights back — pathological nesting, template syntax the tokenizer reads as tags — format a fragment at a time; the structure of the whole usually reveals itself from two or three representative pieces.
Frequently asked questions
What does an HTML formatter do?
It re-indents HTML so the structure is visible: each block-level element starts on its own line, nested elements indent one level deeper than their parent, and closing tags line up with their openers. Minified HTML — which ships as one enormous line to save bytes — becomes readable again, and hand-written HTML with drifting indentation becomes consistent. This formatter tokenises the markup properly rather than guessing with line breaks, treats the HTML void elements (img, br, input and friends) as self-contained, and leaves the contents of script, style, pre and textarea blocks untouched, because whitespace inside them can be meaningful.
Is it safe to paste private HTML here?
Yes — the formatting happens entirely in your browser. Nothing is uploaded, stored or logged; you can verify it by loading the page and disconnecting from the network before pasting. That design is deliberate: HTML often contains unpublished content, internal URLs or commented-out credentials, and a formatting tool has no business seeing any of it on a server. The same local-only rule applies to every tool on this site, but it matters most for developer tools that people paste real work into.
Will formatting change how my page renders?
Almost never — browsers ignore whitespace between block elements — with one well-known exception: whitespace between inline elements is rendered as a space. If two spans or links sit side by side with no gap intended, putting them on separate lines introduces a visible space. Inline-heavy fragments (navigation links, icon rows, button groups) are where this bites. The safe workflow: format a copy, preview it, and keep the original until the preview checks out. Formatters trade a small rendering risk for a large readability gain, which is why formatting on commit, with a visual check, is standard team practice.
What is the difference between formatting and validating?
Formatting is about appearance; validation is about correctness. A formatter will happily indent invalid HTML — an unclosed tag gets indented as confidently as a valid one — while a validator (such as the W3C's) checks the document against the HTML specification and reports errors. They answer different questions: 'can I read it?' versus 'is it right?'. This tool formats, and its tokenizer makes a reasonable structure even of imperfect markup, but a page that renders oddly after formatting needs a validator and a look at the browser's own error console, not a different indent size.
Can I minify HTML again with this tool?
That is the opposite job, and a different tool's: minifiers strip comments and collapse whitespace for production. This site's CSS Minifier does that job for stylesheets; for HTML itself, most teams minify inside their build pipeline rather than by pasting into a page. The two directions are a pair — minify for the bytes you ship, format for the code you read — and in a real pipeline both are automated (the source stays formatted, the build minifies). But for a quick look at how a page is put together, including pages you did not write, pasting the shipped, minified HTML into this formatter is the fastest route to understanding it.
Related tools
Figures checked on 24 November 2026. Everything is calculated in your browser — nothing you type is sent anywhere.