HTML Formatter
Beautify and indent messy HTML, or minify it. Choose 2/4 spaces or tabs, preserve script and style blocks, copy or download — all in your browser.
About the HTML Formatter
This free HTML formatter cleans up tangled markup in seconds. Paste minified, machine-generated or hand-edited HTML and it re-indents every tag by nesting depth so the structure is instantly readable. You choose 2-space, 4-space or tab indentation, and the output is ready to copy or download as a .html file.
The formatter understands the parts of HTML that trip up naive tools: void elements like <br> and <img> never open a phantom block, and the contents of <script>, <style>, <pre> and <textarea> are preserved verbatim so your code and whitespace-sensitive content stay intact. A Minify button does the reverse, stripping comments and collapsing whitespace to ship the smallest file.
Everything runs locally in JavaScript — no upload, no server round-trip — so it is safe to paste internal templates, email HTML or production markup. It works offline once the page has loaded.
How to Use the HTML Formatter
- 1Paste your HTML into the input box.
- 2Pick 2 spaces, 4 spaces or tabs for indentation.
- 3Click Format to beautify, or Minify to compress.
- 4Copy the result or download it as a .html file.
Frequently Asked Questions
Does the formatter change my HTML's meaning?
No. It only adjusts whitespace and indentation between tags — it never adds, removes or reorders elements or attributes. The contents of script, style, pre and textarea are left byte-for-byte unchanged so nothing whitespace-sensitive breaks.
Can it handle broken or partial HTML?
Yes, within reason. The formatter is tolerant of fragments and missing closing tags — it indents what it can rather than refusing. It is a beautifier, not a validator, so it won't report structural errors; use a linter for strict validation.
What does the Minify option do?
Minify collapses runs of whitespace to single spaces, removes indentation and strips HTML comments, producing the smallest equivalent markup. It's useful for shaving bytes off templates before shipping, though a full build tool will usually go further.
Is my HTML uploaded anywhere?
Never. All formatting happens in your browser with JavaScript. The markup is not sent to any server, logged or stored, which makes the tool safe for confidential internal templates and works even offline.