What the minifier removes
The routine is deliberately small. It runs five steps in order, and nothing else is rewritten:
- Every
<pre>,<textarea>,<script>and<style>block is set aside untouched. - If "Strip comments" is ticked, all
<!-- ... -->comments are deleted. - Every run of whitespace, including line breaks and tabs, becomes one space.
- A whitespace gap between two tags is removed only when at least one of them is block-level (
html,head,body,div,p,pre, lists includingdl,dtanddd, tables with their rows, cells, captions and column groups,section,header,footer,nav,main,article,aside,address, headings,figureandfigcaption,fieldsetandlegend,detailsandsummary,dialog,menu,search,form,blockquote,optionandoptgroup,template,meta,link,script,styleandtitle). Between inline tags the gap stays as a single space, and so does the gap beside inline or replaced elements such asa,img,input,button,label,select,textarea,video,audio,iframeandcanvas. Tags are read quote-aware, so a>inside an attribute value does not end the tag. - The protected blocks are put back, and the ends are trimmed.
Worked example
A 187-character page with indentation, an HTML comment and a <pre> block, run with comments stripped, comes back as 136 characters, a saving of 27% as the Stat boxes report it:
<!DOCTYPE html><html><head><title>Demo</title></head><body><p>Hello <b>bold</b> <i>italic</i></p><pre> keep
this</pre></body></html>
The comment and all indentation are gone, the space between bold and italic is still there, and the two-space indent inside the preformatted block survived. Pages with deep indentation and many comments shrink the most, and already-compact markup barely changes.
Where it can change how a page looks
- Runs of spaces collapse to one. Browsers already display several spaces in normal text as one, so nothing visible changes. If you need a wider gap, use
or CSS, which are not touched. Only the<pre>and<textarea>blocks keep their exact spacing. - Conditional comments such as
<!--[if IE]>are deleted as ordinary comments when stripping is on. - Inline CSS and JavaScript are kept as written. To compress them, run them through the CSS minifier and JS minifier first.
- No attribute rewriting. Quotes, optional closing tags and boolean attributes are left alone, which is why the saving is smaller than with a build-time tool. The one exception is whitespace: a run of spaces or line breaks inside an attribute value, such as
title="a b", is collapsed to a single space like everywhere else outside the protected blocks.
Reading the numbers
Original and Minified are character counts of the text, not bytes on the wire. Servers normally apply gzip or Brotli on top, and those algorithms already squeeze repeated whitespace well, so the real-world gain from minifying is smaller than the percentage shown. Always test the output in a browser before replacing your live file.
When this tool fits
Sites built with a framework normally minify as part of the build, which can also rewrite attributes and drop optional tags. This page suits one-off jobs where no build exists: a hand-written landing page, an HTML email template, an embed snippet or a block of markup for a CMS field with a length limit. Keep your readable source file, since minified markup is awkward to edit later.