HTML Minifier

Minify HTML safely: strip comments, collapse whitespace and drop spaces around block tags while keeping pre, textarea, script and style exactly as they are.

Output

Runs entirely in your browser. Your data is never uploaded.

Related Tools

View All

What is HTML Minifier?

The HTML Minifier makes HTML smaller with conservative, rendering-safe transformations: comments are removed, runs of whitespace become one space, and whitespace next to block-level tags is dropped. Content of <pre>, <textarea>, <script> and <style> is kept byte-for-byte.

How to use HTML Minifier

  1. Paste the HTML into the input box.
  2. Click Minify (the output also updates while you type).
  3. Check the size line to see how much was saved.
  4. Copy or download the minified HTML.

Example

Input
<div>
  <!-- c -->
  <p>Hello   <b>big</b>
 world</p>
  <pre>  a
 b</pre>
</div>
Output
<div><p>Hello <b>big</b> world</p><pre>  a
 b</pre></div>

When to use HTML Minifier

Use it for static pages, email templates or HTML snippets embedded in code. Gains are modest compared with gzip/brotli. It does not remove optional tags or attribute quotes, so the output stays valid and predictable.

How HTML Minifier works

A small tokenizer splits the input into tags, text, comments and raw-text blocks. Comments are dropped except Internet Explorer conditional comments (<!--[if …]>). In text, any whitespace run becomes a single space; leading/trailing spaces are removed when the neighbour is a block-level tag such as div, p, li or table, but kept between inline elements (<b>a</b> <i>b</i>), where they are visible. Whitespace inside tags is normalised; attribute values are not changed. JavaScript and CSS inside the page are not minified – use the JS or CSS Minifier for that.

Common Use Cases

  • Shrinking HTML email templates
  • Compacting HTML fragments stored in JSON or databases
  • Removing developer comments before publishing
  • Preparing inline HTML for JavaScript strings

Security Note

Everything runs locally in your browser; the code you paste is not uploaded.

FAQs

Why is the space between two inline tags kept?

Because it is visible on the page. Removing it would join the words.

Are scripts and styles minified?

No, they are kept as-is. Use the JS Minifier or CSS Minifier for them.

Is the output still valid HTML?

Yes. Only comments and insignificant whitespace are removed.

Good next steps

Explore more categories