
Options
Paste HTML on the left and a minified version appears on the right as you type, with the size saved shown before and after gzip. The minifier removes comments and the whitespace browsers ignore, shortens attributes, and minifies the CSS in <style> tags and style attributes. It also strips comments and indentation from inline JavaScript. It understands HTML the way a browser does: whitespace inside <pre> and <textarea> is kept, the space in Hello <b>world</b> is kept, and IE conditional comments are kept. Each result is parsed and compared with the original, and a Same page structure badge confirms the browser builds the same page from both. Nothing is uploaded.
How to minify HTML
- Paste your HTML, or click Open file to load an .html file. You can also drag a file onto the pane.
- Choose how much whitespace to remove. Remove between block elements gives the smallest result. Collapse only turns every run of spaces and line breaks into a single space, which never changes how the page looks.
- Turn individual options on or off, and watch the size change.
- Click Copy, or Download to save the file with
.minadded to its name.
What the minifier changes
| Before | After | Option |
|---|---|---|
<!-- Main nav --> | Removed | Remove comments |
</li> line break and indent <li> | </li><li> | Whitespace |
<p>Hello <b>world</b></p> | <p>Hello <b>world</b></p> | Whitespace (one space kept) |
class=" card wide " | class="card wide" | Shorten attributes |
checked="checked", disabled="" | checked, disabled | Shorten attributes |
<script type="text/javascript">, <form method="get"> | <script>, <form> | Shorten attributes (these are the defaults) |
class="", style="" | Removed | Shorten attributes |
href="/about" | href=/about | Remove attribute quotes (only when safe) |
<br /> | <br> | Drop /> on void tags |
body { margin : 0 ; } | body{margin:0} | Minify inline CSS |
| Indented JavaScript with comments | Same code, comments and indentation removed | Clean inline JS and JSON |
What it never changes
- Text inside
<pre>,<textarea>, and SVG<text>elements. - The single space between inline elements, so
<button>A</button> <button>B</button>keeps its gap. - IE conditional comments (
<!--[if IE]>), comments starting with<!--!, server-side includes, and Knockout comment bindings. - Anything between two
<!-- htmlmin:ignore -->comments. - Line breaks in JavaScript, because removing them can change what code does through automatic semicolon insertion. For full JavaScript minification, run the scripts through a JavaScript minifier.
- PHP, ASP, and other
<? ?>or<% %>blocks, and scripts with non-JavaScript types such astext/template.
The minifier was tested by minifying dozens of real web pages and comparing the page each version produces in Chrome. They were identical except for pages with invalid markup, such as an unclosed <a> tag, which browsers repair in slightly different ways depending on the whitespace around it. The Same page structure badge runs the same comparison on your HTML.
Is minifying HTML worth it?
Typical savings are 5 to 20% for hand-written HTML, and more for HTML with lots of indentation, comments, or inline CSS. After gzip or Brotli compression, which most servers apply automatically, the difference is smaller, usually a few percent, because compression already handles repeated whitespace well. The tool shows both numbers so you can judge.
Minification matters most for large pages, HTML emails (where clients like Gmail clip messages over 102 KB), HTML embedded in JavaScript or JSON, and pages served without compression. For most sites, the bigger wins are optimizing images, CSS, and JavaScript, but minified HTML is free once it's part of your build.
Frequently asked questions
Will minifying HTML break my page?
Not with valid HTML. Only whitespace that browsers ignore is removed, inline spacing and preformatted text are kept, and the result is compared with the original after parsing. If the structure badge shows a difference, your HTML has invalid markup; choose Collapse only, which never changes the layout, and fix the markup when you can.
Is it safe to remove quotes from attributes?
Yes, when the value has no spaces, quotes, equals signs, angle brackets, or backticks, which is what the HTML standard allows. The minifier only removes quotes in that case and keeps them on SVG and MathML elements. Turn the option off if another tool in your pipeline expects quoted attributes.
Does it minify CSS and JavaScript too?
It minifies CSS inside style tags and style attributes, removing comments, spaces, and the last semicolon in each rule. For JavaScript it removes comments, indentation, and blank lines, compacts JSON-LD and other JSON scripts, and leaves line breaks so the code behaves exactly the same. External .css and .js files aren't affected.
How much smaller will my HTML get?
It depends on how it was written. Pretty-printed HTML with comments and inline styles often shrinks 15 to 30%, while HTML generated by a CMS may already be compact. The status line shows the exact saving, plus the gzipped sizes, which reflect what actually goes over the network.
Can I minify templates like PHP, Jinja, or Handlebars?
Template tags such as <?php ?>, {{ }}, and {% %} are kept, but whitespace around HTML tags is still removed, which can matter if your template outputs text there. For the most predictable result, minify the rendered HTML, or use Collapse only.
Is my HTML uploaded?
No. Minification runs in your browser, and your code is never sent to a server.
