HTML Formatter
Beautify HTML with clean indentation, or minify it.
What is HTML Formatter
The HTML Formatter beautifies HTML with 2-space indentation or minifies it by stripping extra whitespace and comments. Script and style block contents are preserved untouched. Everything runs locally in your browser.
🔒 Everything runs in your browser. Nothing is uploaded.
What this tool actually does with your file
- Where it runs
- In your browser, on this page
- Upload
- None — the file never leaves your device
- Offline
- Works with the network disconnected
Format or minify, with different risks
Format mode re-indents by tag depth and puts attributes on the opening tag line. Minify mode removes whitespace between tags and collapses runs inside text. The input limit is 2 MB, which is roughly a large single page and well beyond anything hand-edited.
Minifying HTML is riskier than minifying JSON, because in HTML whitespace is sometimes content. Inline elements separated by a space — <b>a</b> <i>b</i> — rely on that space to render apart; removing it joins the words. Block-level structures are safe, inline ones are not.
Content that must not be reindented
<pre>, <textarea> and <script> hold whitespace-sensitive content. Re-indenting inside <pre> changes how code samples render; collapsing whitespace inside <textarea> changes the default value the user sees. A formatter that treats them like ordinary elements quietly alters the page.
Inline SVG has the same character: an extra space between <text> and <tspan> can shift baseline alignment. For SVG, prefer formatting the file as XML and checking the rendering afterwards.
The check that catches everything
Render both versions and compare screenshots, or at minimum diff the extracted text content. A byte diff will show hundreds of changes that do not matter; a text-content diff shows only the ones that do.
Also remember that formatted HTML and well-formed HTML are different claims. Unclosed <p> and <li> tags are legal in HTML5 and a strict XML-style formatter will either reject them or insert closing tags that change the DOM tree.
How to use it
- 1.Paste your HTML
- 2.Pick Format or Minify
- 3.Run and copy the result
How HTML Formatter works under the hood
Formatters parse your input into a structure, then serialise it back with consistent indentation. That is why a formatter can also reveal a syntax error: if it cannot parse, it cannot print.
- 1
Parse into a tree
JSON goes through JSON.parse; YAML, XML, CSS and SQL use their own parsers. The parse either succeeds with a structure or fails at a line and column.
- 2
Serialise with a fixed style
Indentation width, key order and quoting are applied deterministically, so formatting the same input twice gives identical bytes.
- 3
Show the error position
When parsing fails, the message includes the position so the fix is obvious instead of guessed.
Processing pipeline
Formatting is not validation
A formatter proves the document is syntactically parseable. It does not prove it is valid against a schema, and it does not check business rules. JSON with a duplicated key parses fine and silently keeps the last value.
What gets normalised
Comments are preserved in CSS and SQL but not in JSON, which has no comment syntax. YAML anchors may be expanded, and quote style may change. Keep the original when exact byte layout matters, such as signed payloads.
Verify it yourself
Formatting is deterministic and local — run it twice and compare.
- 1.Open DevTools on this page and switch to the Network tab
- 2.Keep the filter on Fetch/XHR and run the tool
- 3.Confirm no request carries your file — you should see only page assets and fonts
Frequently asked questions
Is script/style content safe?
Yes — both formatting and minifying keep <script> and <style> contents exactly as they are.
What does minify remove?
Only HTML comments (IE conditional comments are kept) and whitespace between tags. Attribute values are untouched.
What this kind of conversion cannot keep
Formatters parse the input into a tree and print it back with consistent indentation. If the input is invalid, you get the parser's error position instead of a silently mangled file — malformed JSON stays malformed rather than being «repaired» into something that is no longer yours.
More in Format
On this page
- What is HTML Formatter
- What this tool actually does with your file
- How it actually behaves
- How to use it
- How it works inside
- Frequently asked questions
Excel formula reference
29 functions with syntax, arguments and a table you can retype.
Browse the list →