Boneyard Tools

HTML Minifier

Paste HTML and compress it as you type. The minifier deletes comments and collapses insignificant whitespace, including the gaps between tags, while leaving the contents of pre, textarea, script and style elements exactly as written. A badge reports the original and minified byte sizes and the percent saved, and you can copy the result or download it as minified.html.

How to minify HTML

  1. Paste or type your HTML into the HTML box, or click Load sample to try it.
  2. Watch the Minified box update instantly below the input.
  3. Check the badge above the output for the original size, minified size and percent saved.
  4. Copy the result with the Copy button, or save it with the download button as minified.html.

Examples

Strip a comment and collapse whitespace

<!-- nav -->
<div class="box">
  <p>Hello   world</p>
</div>
<div class="box"><p>Hello world</p></div>

Preserve whitespace inside pre

<div>  <pre>a  b</pre>  </div>
<div> <pre>a  b</pre> </div>

Keep an IE conditional comment, drop a normal one

<div><!--[if IE]>legacy<![endif]--><!-- normal --></div>
<div><!--[if IE]>legacy<![endif]--></div>

Frequently asked questions

Is my HTML sent to a server?

No. Minification runs entirely in your browser, so your markup never leaves your device.

How does HTML minification reduce file size?

It deletes comments and collapses repeated spaces, tabs and line breaks, including the whitespace that sits purely between two tags, so the same page ships in fewer bytes.

Will it break my inline scripts, styles or preformatted text?

No. Content inside pre, textarea, script and style tags is passed through exactly, so code, CSS and whitespace-sensitive blocks stay intact even though the surrounding markup is compressed.

Does it also minify the CSS or JavaScript inside those tags?

No. Because script and style contents are preserved verbatim, their whitespace and comments are left alone. Run a dedicated CSS or JavaScript minifier on those blocks if you want them compressed too.

Are IE conditional comments kept?

Yes. Conditional comments such as an if lt IE 9 block are load-bearing, so any comment containing an [if condition or an endif marker is detected and left in place while ordinary comments are removed.

Can collapsing whitespace ever change how the page renders?

Usually not, but there is one edge case. Whitespace between two tags is removed entirely, and a run of whitespace elsewhere becomes a single space. For inline elements like span or img, the difference between a single space and no space can shift spacing slightly, so review inline-sensitive layouts after minifying.

How is the percent saved calculated?

It compares the UTF-8 byte length of your input against the minified output, then reports the reduction as a percentage rounded to one decimal place. Multi-byte characters therefore count by their true byte size, not by character count.

Does it remove optional closing tags, quotes or shorten attributes?

No. The minifier only removes comments and insignificant whitespace. It never drops closing tags, unquotes attributes or rewrites your markup structure, so the output stays a faithful, well-formed version of the input.

Should I still gzip if I already minify?

Yes. Minification and gzip or brotli compression are complementary. Gzip does the heavy lifting on repeated strings during transfer, while minification removes bytes the compressor cannot recover, and together they beat either one alone.

Learn more

Related tools