HTML Minifier
Minify HTML by removing comments, whitespace, and empty attributes.
Recommended tools
Free CDN, DNS, and edge hosting for developers.
Affordable domains and SSL certificates.
Affiliate links — we may earn a commission if you sign up.
About the HTML Minifier
The HTML Minifier compresses markup without breaking its meaning, and the key is what it refuses to touch. Content inside pre, code, textarea, script, and style elements is treated as raw text and preserved verbatim, so indented code samples, inline JavaScript, and CSS blocks keep their exact formatting while everything around them collapses. Three switches control the output: Strip comments removes <!-- --> blocks, Collapse whitespace squeezes text nodes to single spaces and trims the seams around tags, and Remove empty attributes deletes pairs like class="" or value="" from opening tags. Void elements such as meta, input, img, and br are recognized as self-closing so they never trigger raw-text mode, and the doctype is passed through untouched. The bundled sample is a full page — header, style block, pre-formatted function, code snippet, an input with an empty value attribute, and an inline script — so loading it demonstrates every feature at once. Byte-size stats quantify the savings, and the result downloads as page.min.html.
Examples
<div class="card"> <!-- promo banner --> <h1>Welcome</h1> <p class="">Build tools that ship.</p> </div>
<div class="card"><h1>Welcome</h1><p>Build tools that ship.</p></div>
<pre>
function greet(name) {
return "Hi, " + name;
}
</pre><pre>
function greet(name) {
return "Hi, " + name;
}
</pre><input type="text" value="" placeholder="Search" disabled />
<input type="text" placeholder="Search" disabled />
How to use
- 1
Paste your markup into the HTML input textarea, or click Load sample.
- 2
Set the switches: Strip comments, Collapse whitespace, Remove empty attributes.
- 3
Watch the Minified HTML result box update live.
- 4
Read the Original, Minified, Saved, and Savings stats to quantify the result.
- 5
Download the output as page.min.html.
Common use cases
- Shrinking a static page before inlining it into an email or embed.
- Comparing markup weight before and after removing comments in templates.
- Cleaning generated HTML from WYSIWYG editors that emit empty attributes.
- Preparing compact partials for a server that serves cached fragments.
- Quantifying how much of a page is whitespace before a CMS migration.
- Producing tidy snippets for documentation without manual clean-up.
Best practices
- Trust the raw-text list: pre, code, textarea, script, and style content is never collapsed — do not expect savings there.
- Remove empty attributes only when you are sure no framework reads their presence (some treat empty vs absent differently).
- Keep comments that carry licenses or conditional logic; strip the rest.
- Verify script content survives intact — the tool preserves it verbatim, including spaces that matter inside strings.
- Minify templates before caching, not the source files you still edit.
- Spot-check text nodes between inline elements, since collapsed spaces can change spacing in rendered prose.
Tips
- Load the sample page first — it contains a pre block, a style block, a script, and an empty attribute in one file.
- Watch the Saved stat jump when stripping large comment blocks from templates.
- Toggle Remove empty attributes off when minifying markup for frameworks that detect attribute presence.
- Download page.min.html and diff it against the source to review exactly what changed.
Frequently asked questions
Explore more developer tools
Browse the full collection of developer tools on the hub, or jump back to all categories.