HTML Minifier

Minify HTML to shrink page size — comments stripped and whitespace collapsed, while pre, script, style and conditional comments are kept. Free, no upload.

Conditional <!--[if]--> and important <!--! comments, and the contents of <pre>, <textarea>, <script> and <style>, are always preserved.

Minified HTML
<!DOCTYPE html><html lang="en"><head><title>My Page</title><style>
      .btn { color: #fff; }
    </style></head><body><h1>Hello, world</h1><p>This is a <b>demo</b> paragraph.</p><pre>  keep   this
    exactly  </pre></body></html>

298 → 232 bytes (22% smaller)

🔒 Minified in your browser — nothing is uploaded.

What this HTML minifier does

Paste your markup and this tool returns a compact, production-ready version. It strips <!-- --> comments, collapses runs of spaces, tabs and newlines between and inside tags to a single space, removes the whitespace-only gaps between block elements, and trims the document. The output updates live as you type and a size indicator shows exactly how many bytes you saved, so you can drop the result straight into your build. Two independent toggles let you collapse whitespace and remove comments on their own.

Safe, predictable minification

This minifier is deliberately conservative and never rewrites your tags or attributes. The contents of <pre>, <textarea>, <script> and <style> are preserved verbatim, conditional <!--[if IE]> comments and important <!--! notices are kept, and a > inside a quoted attribute value never splits a tag. A single meaningful space is preserved around inline elements so your wording stays intact. The same input always produces the same output, with no server round-trip. Pair it with the CSS minifier, HTML formatter and JSON formatter.

Frequently asked questions

Is my HTML uploaded to a server?

No. All minification happens locally in your browser with JavaScript. Your markup is never sent, stored, or uploaded anywhere, so even unreleased or proprietary pages stay private.

Will minifying break how my page renders?

No. The tool only removes comments and insignificant whitespace and never touches your tags or attributes. It preserves the contents of pre, textarea, script and style, keeps a meaningful space around inline elements, and leaves quoted attribute values alone, so the rendered result is the same.

Does it minify the CSS and JavaScript inside my page?

No. Content inside style and script blocks is preserved exactly as written. To shrink those, run the CSS or JavaScript through a dedicated minifier — this tool focuses on the HTML around them and keeps your code safe.