Free SEO Tools

All tools

HTML Minifier

Strip comments and spare whitespace from HTML while leaving pre, textarea, script and style blocks exactly as they were.

Paste code and press Minify.

How to minify HTML

  1. Paste your HTML into the input box. It can be a full page, a template or a short snippet. Press Load a sample if you want to try it first.
  2. Choose your options. Keep ordinary HTML comments is off by default, so notes such as <!-- page title --> are removed. Conditional comments used by older email clients are always kept.
  3. Only tick Also remove spaces between tags if you are sure it is safe. It saves a few more bytes, but it can join words that sit in neighbouring inline tags.
  4. Press Minify HTML. The line above the output shows the size before and after, and Copy result puts the result on your clipboard.

Worked example

The built-in sample is a small "Opening hours" page of 314 bytes. It contains a comment, deep indentation, a heading written as <h1 class="title" > with stray spaces, and a <pre> block listing times. The sample is minified as soon as it loads, and the result line reads 314 bytes → 252 bytes (19.7% smaller). The comment has gone, each run of spaces and line breaks has become a single space, and the heading tag is now <h1 class="title">. The opening hours inside the <pre> block keep their exact spacing, because in preformatted text every space matters. The page looks exactly the same in a browser, but it is smaller to download.

How it works

The minifier walks through your code and splits it into comments, ordinary tags, text, and protected blocks. Protected blocks are pre, textarea, script and style elements, and they are copied across unchanged, because whitespace inside them can affect how they work. Inside tags, extra spaces between attributes are removed while anything inside quotation marks is left alone, so attribute values stay intact. In text, any sequence of whitespace becomes one space, which is how browsers display it anyway. Everything happens in your browser, and your code is not uploaded.

When minifying is worth it

Minifying makes the most difference on pages built from long hand-written templates, pages full of developer comments and HTML emails, where some providers clip messages above a certain size. Gmail, for example, cuts off emails larger than about 102 KB and hides the rest behind a "View entire message" link. Trimming whitespace and comments can bring a newsletter back under that limit. For a typical blog post generated by a modern CMS, the gain is smaller, but it is still free to have.

Tips

  • Minify a copy, never your only source file. Readable code is much easier to edit later.
  • Minify inline CSS and JavaScript separately with the matching tools, because this one deliberately leaves script and style blocks alone.
  • If your server already uses gzip or Brotli compression, savings from minifying are smaller, but they still add up across many pages.
  • After minifying, open the page and check any spacing between links, buttons and bold words, especially if you used the aggressive option.
  • Remove comments that reveal private notes, file paths or old code before you publish, even if you do not minify anything else.

Frequently asked questions

Will minifying change how my page looks?

With the default settings, no. Browsers already collapse repeated whitespace, so removing it does not alter the layout.

Does it work on WordPress or PHP templates?

It is designed for finished HTML, such as a page's output or a static template. Server code inside <?php ?> tags is not understood, so minify the HTML a page produces rather than the PHP file itself.

How much will my page speed improve?

Usually a little. Minifying HTML typically saves 5–20% of the markup, and images or scripts often matter more.

Is my code stored?

No. It stays in your browser tab and disappears when you close or refresh the page.