About the HTML Minifier
Every byte of a page has to travel over the network, and on slow mobile connections smaller pages load noticeably faster. This HTML minifier removes what browsers do not need, such as comments, indentation and whitespace between tags, while protecting the spaces that matter between inline elements and the exact contents of pre and textarea blocks, so the page looks the same afterwards. It shows the original size, the new size and the saving. Most servers also compress pages with gzip or Brotli, so minification and compression together give the best result. To make minified markup readable again, use the HTML Formatter, and for stylesheets, the CSS Minifier.
Not every space in HTML can be thrown away, and that is exactly where many minifiers damage pages. When two inline elements sit side by side, the gap between them is displayed as a real space, so deleting it glues neighbouring words together. Text in pre and textarea elements is shown exactly as typed. This tool protects both cases, which makes the result a little larger than an aggressive minifier would produce but keeps the page looking the way you designed it.
The before and after sizes are shown in bytes, along with the percentage removed. Treat that number realistically: when a server already applies gzip or Brotli, the whitespace being removed compresses to almost nothing, so the reduction in what actually travels over the network is usually a few percent. Minifying is still a sensible step in a build, just never one worth risking a broken layout for.
How to use the HTML Minifier
- Paste the HTMLA complete page or just a fragment.
- Choose what goesComments, whitespace between tags and, if you want, quotes that are not needed.
- Run MinifyThe compact markup appears along with the size comparison.
- Take it awayCopy the result or download it as a file.
HTML Minifier features
- Strips comments, with a switch to spare conditional ones
- Whitespace between block-level tags collapsed
- pre, textarea, script and style content protected
- Meaningful gaps between inline elements left in place
- Can drop attribute quotes the specification does not require
- Before size, after size and percentage saved
- Copy or download the minified page
Common uses
- Making a page lighter right before it is deployed
- Shrinking the markup of an HTML email
- Compacting an HTML snippet that is stored inside a script
- Seeing how much of a template is just indentation
- Preparing a self-contained single-file HTML document
Minifying HTML in practice: real savings with compression, Gmail's clipping limit, checking server compression and what matters more
Minifying HTML removes comments and needless whitespace, and it is easy to overestimate what that achieves. This guide measures a real page, explains why compression changes the picture, and shows where minification genuinely matters, such as keeping newsletters under Gmail's clipping limit. It also covers checking that your server compresses pages, minifying as part of a build and the bigger performance wins worth tackling first.
A worked example: measuring a real page
A formatted version of a real tool page measured 65,222 bytes, and minifying it brought it down to 48,833 bytes, a saving of about 25 percent. With gzip compression, which servers apply before sending, the formatted page shrank to 11,518 bytes and the minified one to 10,097, so the saving in transferred size was about 12 percent. Minification still helps, but compression does most of the work.
Gmail's clipping limit
Gmail clips email messages larger than about 102 KB, hiding the rest behind a View entire message link. Anything below the cut, including unsubscribe links and tracking for opens, may never load. Newsletter templates exported from builders are often bloated with whitespace and comments, and minifying them is one of the simplest ways to stay under the limit.
Checking server compression
Before worrying about whitespace, confirm the server compresses HTML at all. Running curl -sI -H "Accept-Encoding: br,gzip" followed by a page address should show a content-encoding header with br or gzip. If it does not, enabling compression on the server saves far more than any minifier.
Minify during the build
Minified files are hard to edit, so keep readable source files and generate minified versions automatically when deploying. Static site generators, build tools and caching plugins can all do this. Hand-minifying pages means every future edit starts by reformatting, and mistakes creep in.
Caching plugins
WordPress caching plugins often include an option to minify HTML. Turn it on, then check pages carefully: inline scripts, forms and page-builder layouts occasionally break when whitespace changes. If something looks wrong, disable the option for that page type, or exclude specific inline scripts, rather than abandoning caching altogether.
Aggressive options
Some minifiers can also remove optional closing tags, such as those for list items and paragraphs, and quotes around attribute values. Browsers handle this correctly because the HTML standard allows it, but other tools that read your pages, such as email clients or scrapers, may not. The extra few bytes rarely justify the risk.
What matters more
For page speed, images, render-blocking scripts and stylesheets, web fonts and third-party tags usually matter far more than HTML whitespace. Optimising the largest image on a page often saves more than minifying every page on the site. Use HTML minification as a finishing touch after the bigger wins.
Testing after minifying
After enabling minification, check pages with inline elements side by side, such as links within sentences and buttons in a row, to make sure spacing has not changed. Also test forms, embedded videos and anything using inline scripts, as these are the most likely places for minification problems to appear.
Measuring on your own site
To measure your own pages, save the HTML as delivered, then compare its size before and after minifying, and again after compressing both with gzip. Results vary by page: pages with heavy indentation and many comments gain the most, while pages already produced by modern build tools may gain very little.
Common mistakes
- Minifying by hand instead of during deployment.
- Expecting headline savings when compression is already enabled.
- Ignoring Gmail's clipping limit for newsletters.
- Using aggressive options that other tools cannot read.
Related tools
To make minified markup readable again, use HTML Formatter. For stylesheets, try CSS Minifier, and for scripts, JavaScript Minifier.
Inline styles and scripts
Some HTML minifiers leave the contents of inline style and script blocks unchanged. Large inline blocks are better moved into external files, which browsers can cache between pages, or minified separately with tools built for CSS and JavaScript. Small critical snippets can stay inline once minified.
Minify the output, not the templates
Templates mixing HTML with server code or template logic should stay readable. Minify the HTML they produce, either during a static build or through a caching layer that processes rendered pages. Minifying template source files directly makes them hard to maintain and can break template syntax.
Purge caches after changes
Sites behind Varnish or a CDN serve stored copies of pages. After turning on minification, purge the cache so every page is regenerated in the new form. Otherwise some visitors receive old copies and others new ones, which makes any problems introduced by minification harder to spot and reproduce.
Prioritising with performance reports
Tools such as PageSpeed Insights and Lighthouse list the largest opportunities on a page, with estimated savings for each. Images, unused JavaScript and render-blocking resources usually top the list, well above whitespace. Working through the list in order of estimated savings gets a site faster much sooner than polishing markup first.
Privacy
Minification runs in your browser. Your markup is not uploaded or stored.
Frequently asked questions
Is there any risk of breaking my page?
Only if whitespace that changes the rendering gets removed, and that is precisely what this tool refuses to do: gaps between inline elements and everything inside pre or textarea are kept. It is still wise to look at the page before and after publishing it.
How large is the real saving?
Measured on the raw file, often twenty to forty percent. Measured after gzip or Brotli, which already squeeze runs of spaces down to almost nothing, the difference usually shrinks to low single digits, so treat minifying as a small gain rather than a major speed fix.
Will every comment be removed?
By default, yes. You can tell the tool to spare conditional comments, because some older desktop email clients, Outlook in particular, still act on them, and email templates that rely on them would otherwise stop working.
What is the attribute quote option for?
Quotation marks are optional around simple attribute values such as class=nav, and this option deletes them where the specification allows it. The output stays valid, yet it becomes harder to read and edit by hand, so the setting is off until you choose it.
Can I turn minified HTML back into readable code?
Paste it into the HTML Formatter to bring the indentation back. Any comments that were stripped are gone permanently, so keep your source file and only minify a copy.
Is my markup sent to a server?
No. The whole process happens in your browser, so the page you paste in, including drafts and anything that is not yet published, stays on your own device and is never stored.