HTML minifier
Strip HTML comments and redundant whitespace, drop optional closing tags and squeeze inline CSS/JS — keeping pre/textarea/script/style intact — with before/after size and compression ratio.
Runs in your browserEvery computation happens in your browser — your data never leaves this device.
Minified output
<!DOCTYPE html><html><head><style>body{margin:0;padding:0}</style><body><div class="card"><p>Hello world<pre> 保留 空白 </pre></div><!--[if IE]><p>IE</p><![endif]--><script>const name = 'UniKit';
console.log(name);</script>pre and textarea content, plus strings, regexes and template literals inside scripts, are preserved verbatim.
Size
395 bytes230 bytes165 bytes41.77%1What this tool does
- Shrink HTML before shipping by dropping comments, indentation and redundant whitespace so the page parses faster.
- Minify inline <style> and <script> blocks too — handy for email templates and embedded snippets that cannot reference external files.
- Compare byte counts before and after to measure what comment removal and whitespace collapsing actually save.
- Diagnose layout differences: minify once with whitespace collapsing off to see whether a gap comes from HTML whitespace or from CSS.
Example
Input
<div class="card"> <p>Hello <b>UniKit</b></p> <!-- comment --> <pre> a b </pre> </div>
Output
<div class="card"><p>Hello <b>UniKit</b> <pre> a b </pre></div>
110 bytes become 68 (42 saved, 38.18% smaller, 1 comment removed). The spaces and newline inside <pre> survive untouched, while optional closing tags such as </p> are dropped.
Frequently asked questions
Can minifying change the layout?
With the default options the whitespace between block elements is removed and runs of spaces between inline elements collapse to one, so nothing moves visually. The one subtlety is a newline between two inline elements: it still becomes a single space rather than disappearing, so words do not run together.
Is the content of pre and textarea preserved?
Yes. Both are whitespace-sensitive, so once the minifier enters them it stops collapsing whitespace and copies the original spaces and line breaks. Strings, regexes and template literals inside <script> and <style> are likewise left alone.
Why is my <!--[if IE]> conditional comment still there?
Because "keep conditional comments" is on by default — old templates still use them to feed content to specific browsers. Turn the option off if you want them removed along with the normal comments.
Is it safe to drop closing tags like </p> and </li>?
Yes. HTML5 allows a closing tag to be omitted for p, li, dt, dd, option, tr, td, th, thead and a few others, and browsers close them implicitly. Only that safe subset is touched — </div> and friends are always kept.
Does minifying the inline JS break it?
No. The JS pass only strips comments and indentation and deliberately keeps newlines so automatic semicolon insertion still behaves; strings, template literals and regex literals are copied verbatim. It does no renaming or dead-code elimination — reach for a bundler if you need that.
Keywords:html 压缩minify htmlhtml minifier压缩代码空白折叠whitespacegzip 前处理