Developer Tools

HTML Minifier

Minify HTML code to reduce file size.

How to Use HTML Minifier

1

Paste your HTML into the input box, or upload an .html or .php template file.

2

Choose whether to drop HTML comments and whether to leave script and style blocks as they are.

3

Click the "Process" button to collapse whitespace, trim optional closing tags, and shorten attributes.

4

Copy or download the minified markup, then diff it against your original before shipping to be safe.

Features

Protects pre, textarea, and inline code whitespace exactly as authored
Optional comment removal, including awareness of conditional comments
Collapses whitespace runs between tags down to a single separator
Shortens boolean attributes and removes redundant type="text/javascript"
Displays original size, minified size, and the percentage saved
Leaves the inside of script and style untouched unless you explicitly ask

Frequently Asked Questions

It rarely does, but there is one classic edge case: two inline-block or inline-flex elements that touch with no whitespace between them, where a removed space lets them overlap. The other common risk is unexpected newlines inside inline elements, which this tool avoids by collapsing rather than deleting.
Usually yes. Most build tools strip them anyway, and they can leak internal notes, ticket numbers, or debugging markers. Conditional comments and any comment marked as legal are worth keeping if you still support legacy Internet Explorer.
Yes. Whitespace inside pre and textarea is rendered content, so the minifier protects those blocks completely. Always give the result a visual pass, especially around code samples in documentation pages.
It is free, needs no account, and handles large documents without a practical cap. There is no watermark and no email requirement, and processing happens in your browser so nothing is uploaded.

About HTML Minifier

Every newline and repeated space in an HTML document is a byte your visitors download and your server compresses. The HTML Minifier collapses that whitespace, strips comments, removes optional closing tags, and shortens attributes so the same page ships as a fraction of its original size. On a markup-heavy page the difference is often 20 to 30 percent before gzip.

Safety is the hard part of HTML minification, and that is where this tool is careful. Text inside pre and textarea is whitespace sensitive, so it is protected completely. Script and style bodies are left alone by default rather than being mangled by a naive whitespace removal. Optional end tags are only dropped where the HTML specification explicitly allows it.

Attributes are normalised too. Boolean attributes lose their redundant value, quote characters around simple values are removed, and the obsolete type="text/javascript" is cleaned up. You get a real byte count before and after, and a diffable output so you can confirm the transformation is safe before shipping it.

When to Use This Tool

  • Shrinking a static page or landing page before it goes to production
  • Reducing the size of an HTML email template while protecting the layout
  • Cleaning a WordPress or Shopify theme file for a production deploy
  • Comparing two versions of a template by their minified output
  • Preparing HTML for embedding in an email client or an in-app webview