HTML Formatter & Minifier
Beautify or minify HTML instantly, with adjustable indentation and comment removal.
About this tool
What this HTML formatter & minifier does
This tool does two opposite jobs in one place. Switch to Beautify mode to take compressed, minified, or just messy HTML and turn it into cleanly indented, readable markup with consistent nesting. Switch to Minify mode to strip out comments and collapse extra whitespace, shrinking the file size for production. Both run entirely client-side with a lightweight parser — your HTML never leaves your browser or touches a server.
How to use it
- Paste your HTML into the input box, or click "Load Example" to try it with sample markup.
- Pick Beautify or Minify from the Mode dropdown.
- In Beautify mode, choose 2 spaces, 4 spaces, or a tab for indentation.
- In Minify mode, toggle whether HTML comments should be stripped.
- The output updates live, along with a character count and (in Minify mode) the percentage reduction.
- Copy the result or download it as an .html file.
What counts as "safe" formatting here
The formatter preserves the exact content of <pre>, <script>, <style>, and <textarea> tags without touching whitespace inside them, since reformatting those can silently change how a page renders or how a script behaves. Everything else gets indented one level deeper for every nested element, with void elements like <br>, <img>, and <input> handled correctly so they don't add an indentation level of their own.
Common use cases
- Cleaning up minified or auto-generated HTML from a CMS export so it's readable for debugging.
- Shrinking a static HTML file's size before deploying it, without setting up a build pipeline.
- Formatting HTML pasted from a chat app or email that lost all its original indentation.
- Quickly checking whether a snippet of HTML is well-formed by seeing how it nests once formatted.
Frequently asked questions
Will minifying break my JavaScript or CSS?
No — content inside <script> and <style> tags is left completely untouched during both beautify and minify, since those need exact whitespace and syntax to keep working correctly.
Does the beautifier fix broken or unclosed HTML tags?
No, this is a formatter, not a validator — it assumes reasonably well-formed HTML and indents it accordingly. If your markup has unclosed tags, the indentation may drift, which is actually a useful visual clue that something's unbalanced.
Can I choose tabs instead of spaces for indentation?
Yes, the Indent dropdown in Beautify mode includes a Tab option alongside 2-space and 4-space indentation.
What does "Remove HTML comments" do in Minify mode?
When checked, every <!-- comment --> in the markup is stripped from the output. Turn it off if you need to keep specific comments, like licensing notices, in the minified file.
Is my HTML uploaded to a server when I use this tool?
No — all formatting and minifying happens locally in your browser with JavaScript. Nothing you paste is sent anywhere.
