← All tools
// DEVELOPER

HTML Minifier online

Minify HTML by removing whitespace and comments — browser-based.

HTML Minifier logo
by
CHUNKY
MUNSTER
HTML MINIFIER

What Gets Removed

How to Use the HTML Minifier

  1. Paste your HTML source into the input box.
  2. Click Minify — whitespace between tags collapses, HTML comments are removed, and the output appears below.
  3. Check the size readout: original bytes, minified bytes, and the percentage saved.
  4. Copy the result or download it as a .html file.

Minified HTML downloads faster and uses less mobile data. The HTML Minifier strips runs of whitespace and removes comments while leaving the contents of <pre>, <textarea>, <script> and <style> blocks alone, so layout, code and pre-formatted text survive the round trip. Conditional comments for legacy IE (<!--[if IE]-->) are also preserved, since those still carry meaning for the browsers that read them.

How the HTML Minifier Works

Minification happens in your browser using a small set of regex passes: collapse whitespace between tags, drop comments, trim leading/trailing space inside tags, and tighten attribute spacing. Crucially, the algorithm walks past <pre>, <textarea>, <script> and <style> blocks without touching their contents — those tags hold whitespace-sensitive content. The output is byte-counted against the input so you can see exactly how much you've saved before copying.

Frequently Asked Questions

How much smaller does HTML usually get after minification?

Hand-written HTML with normal indentation typically shrinks 15–30%. Generated HTML from a templating engine often saves more — 30–50% — because it carries more whitespace per tag. The tool reports the exact byte count and percentage so you can see the saving.

Will minifying HTML break my page?

No, as long as the HTML is well-formed. The minifier preserves the contents of <pre>, <textarea>, <script> and <style> tags so layout and code aren't damaged. It also leaves IE conditional comments (<!--[if IE]-->) intact, since those carry meaning for old browsers.

Should I minify HTML by hand or in a build step?

For static pages or one-off uploads, paste-and-copy is fine. For projects with templating, use a build-step minifier (html-minifier-terser, esbuild) so the source stays readable in version control and minification is automatic on deploy.

Does it minify the inline CSS and JavaScript inside <style> and <script> tags?

No — only the surrounding HTML structure is minified. Inline CSS and JS are left untouched so they keep working exactly as written. Run a dedicated CSS or JS minifier first if you need those compressed.

Pair with the HTML Prettifier when you need to read the output again, or with the CSS Minifier and JavaScript Minifier for full asset compression.