HTML Minifier
Flatten your markup into a single tight line — comments stripped, the whitespace between tags collapsed — and check it parses cleanly before you ship.
How HTML minification works here
HTML is forgiving about whitespace — the browser ignores most of the spaces and newlines you add for readability. A minifier takes advantage of that by removing the inter-tag whitespace and comments that bloat the document without affecting what renders.
Before compressing, this tool runs your markup through htmlparser2 to confirm it parses. Only then does it strip <!-- comments -->, collapse runs of whitespace down to a single space, and remove the gaps between adjacent tags so > < becomes ><.
It's a deliberately conservative minifier: it won't rewrite your attributes or remove optional tags, so the output is predictable. And because it all runs locally, page templates with private content never leave the browser.
Compressing a page in four steps
- 1
Paste your HTML
Add the markup to the input pane, or upload an .html file.
- 2
Let it validate
The parser checks the document; if something is malformed you'll see an error instead of broken output.
- 3
Grab the single-line result
Comments and inter-tag whitespace are stripped, leaving compact markup on the right.
- 4
Copy or download
Take the minified HTML to your clipboard or save it as an .html file.
What you get out of it
Smaller HTML payloads
Removing comments and whitespace trims the document the browser has to download and parse.
Catches malformed markup
Because the document is parsed first, broken or mis-nested tags surface before you deploy.
Cleaner email and template output
Inlined, single-line HTML is handy for email templates and embedding markup as a string.
No round-trip to a server
Your markup is parsed and compressed locally, so unreleased pages stay private.
Before and after
A commented, indented fragment on the left; the collapsed output on the right.
<!-- header -->
<header>
<h1> Welcome </h1>
<p>
Hello there.
</p>
</header><header><h1> Welcome </h1><p> Hello there. </p></header>What this minifier deliberately leaves alone
Aggressive HTML minifiers sometimes remove quotes around attributes or drop optional closing tags. That squeezes out a few more bytes but can subtly change behaviour with some templating engines and downstream parsers. This tool stays conservative: it removes comments and whitespace, and nothing else. If you later need to read the markup again, run it through an HTML formatter to re-indent it.
A note on whitespace-sensitive content
- Text inside
<pre>and<textarea>is whitespace-significant — collapsing it can change what users see. - Inline elements separated by a space (like links in a sentence) can visually run together if that space is removed.
- Review the output for any spacing-dependent layout before shipping it to production.
- When in doubt, keep the readable source in version control and minify as a build step.
Frequently asked questions
No. This tool focuses on the markup — comments and inter-tag whitespace. To compress embedded styles or scripts, copy them out and run them through the CSS Minifier or JS Minifier separately.
Your HTML is run through htmlparser2 before minifying. A parse error usually means a tag isn't closed or is mis-nested. Fix the structural issue and the minified output reappears.
It can, in specific cases. Content inside <pre> or <textarea>, and spaces between inline elements that you rely on visually, are whitespace-significant. Review those areas in the output before deploying.
This tool collapses whitespace globally, so be cautious with <pre> and <textarea> content where every space matters. Check the output if your page contains pre-formatted text.
No. Parsing and minification both happen in your browser, so private templates and unpublished pages never leave your machine.
Yes — paste it into an HTML beautifier to re-indent it. The comments removed during minification can't be recovered, though.
Need another tool?
Browse the full toolbox or dig into the blog for the engineering behind it.