HTML Tools
HTML Minifier
Smaller pages, identical rendering — comments stripped and whitespace collapsed with pre/script/style protected.
In short
Minify HTML online: strip comments and collapse whitespace while protecting <pre>, <script> and <style> blocks. Validates first, shows size savings.
By NaveenKumar T · Updated
- Comment removal
- Whitespace collapsing
- Protects pre/script/style
Runs entirely in your browser — nothing you paste or open here is uploaded, logged, or stored.How we handle data →
Example
HTML Minify: input and output
A newsletter fragment with a plain comment, Outlook conditional comments, a <pre> block and an inline stylesheet.
<!-- newsletter: issue #42 -->
<!--[if mso]><table role="presentation"><tr><td><![endif]-->
<div class="wrap">
<h1>Release notes</h1>
<pre>
npm i sync-cli@3
</pre>
<p>Now with <b>dark mode</b> and <i>faster sync</i>.</p>
<style>
.wrap { max-width: 600px; }
</style>
</div>
<!--[if mso]></td></tr></table><![endif]--><!--[if mso]><table role="presentation"><tr><td><![endif]--><div class="wrap"><h1>Release notes</h1> <pre>
npm i sync-cli@3
</pre> <p>Now with <b>dark mode</b> and <i>faster sync</i>.</p> <style>
.wrap { max-width: 600px; }
</style>
</div><!--[if mso]></td></tr></table><![endif]-->The plain comment vanished but both [if mso] conditional comments survived, the three spaces in the heading collapsed to one, the gaps between ordinary tags were closed, and the <pre> and <style> blocks kept their line breaks and indentation — whitespace touching a protected block is collapsed to a single character, never removed.
Learn more
What HTML minification saves
Templates accumulate indentation and comments that users download on every page view. Minification typically trims 10–25% before compression — and since gzip works better on regular content, some of that saving survives even after transport compression. For high-traffic pages and emails (where size caps clip messages), it's free performance.
The pre-minify validation step matters: minifying structurally broken HTML can change how browsers error-correct it, so this tool refuses to minify markup that doesn't pass the structural check.
Email HTML: where minification is mandatory
Web pages enjoy gzip; email mostly doesn't — and Gmail famously clips messages over 102 KB, hiding your unsubscribe link and tracking pixel along with the content. Email templates are also the most whitespace-heavy HTML in existence (nested-table layouts indented six levels deep), which makes them the best case for minification: 20%+ reductions are routine, often the difference between clipped and delivered. Minify as the last step after testing, keep an unminified master for editing.
The protected-blocks rule matters here too: <style> blocks in email heads pass through byte-for-byte, so the conditional comments and MSO hacks that make Outlook behave survive intact.
Help
Frequently asked questions
Everything you need to know about the HTML Minify.
01How do I use the HTML Minify?
Paste your HTML and press Minify. Comments disappear, inter-tag whitespace collapses, and protected blocks (<pre>, <script>, <style>, <textarea>) pass through untouched. The status bar shows the byte savings.
02Is HTML minification safe for my layout?
Mostly, with one rule to know: whitespace that sits between two tags is removed entirely, so a space between adjacent inline elements (</b> <i>) disappears — keep such spaces inside an element or write . Whitespace next to text is only collapsed to a single space, never deleted, and <pre>, <textarea>, <script> and <style> pass through untouched. Check spacing-critical pages in the HTML Viewer's preview.
03Which comments are kept and which are removed?
Every <!-- … --> comment is stripped except the ones that begin with <!--[if — the conditional comments Outlook and old Internet Explorer read — because email templates rely on them to load MSO-only tables and styles. Comments inside <script>, <style>, <pre> and <textarea> also survive, since those blocks are copied through byte-for-byte. Everything else, including multi-line comments and commented-out markup, is removed before the whitespace pass, which is where most of the size savings on template-heavy pages come from.
Keep working
Related tools
HTML Formatter
HTML Tools
HTML Validator
HTML Tools
JSON Minifier
Compress JSON to its smallest valid form by stripping every unnecessary character — with full validation built in.
XML Minify
Strip every insignificant byte from your XML — smaller payloads for SOAP calls, config files, and storage.
HTML to JADE
HTML Tools
Minify CSS
Strip every byte the browser doesn't need — comments gone, whitespace collapsed, savings shown.