HTML minifier

Minify HTML by removing whitespace, line breaks and comments to shrink page size and speed up loading. See before and after character counts. Free.

Smaller HTML, faster pages

HTML written by people (or generated by page builders) is full of indentation, line breaks and comments. Browsers don't need any of that. The HTML minifier strips out unnecessary characters while keeping the page working the same, and shows the HTML characters before and the minified HTML characters after, so you can see how much you saved.

Smaller HTML downloads faster, especially on mobile networks, and it's the first file the browser needs before it can start rendering anything.

Minify a copy for production and keep your original, readable source for editing.

How to use the html minifier

  1. Paste your HTML code.
  2. Submit to minify it.
  3. Compare the character counts.
  4. Copy the minified HTML and test the page before deploying.

Examples

A small page

Input:

<!DOCTYPE html>
<html>
  <head>
    <title> My page </title>
  </head>
  <body>
    <!-- main nav -->
    <p class="intro">
      Hello   <b>world</b>
    </p>
  </body>
</html>

Output:

<!DOCTYPE html><html><head><title>My page</title><body><p class=intro>Hello <b>world</b>

Whitespace and the comment are gone, the quotes around intro are dropped, and closing tags that HTML allows you to omit (like </p>, </body> and </html>) are removed. Browsers render it the same.

Common uses

  • Reducing the size of static HTML pages and landing pages.
  • Compressing HTML email templates (some email clients clip large messages).
  • Shrinking HTML snippets and widgets embedded on other sites.
  • Preparing production builds when you don't have a build tool.
  • Shrinking HTML email templates before sending, after testing them in the main email apps.

Tips and things to know

  • Keep the original, readable file. Minified code is hard to edit.
  • Whitespace inside <pre> and <textarea> matters; check those parts after minifying.
  • Gmail clips emails over about 102 KB, so minifying large HTML emails can keep them intact.
  • Server compression (gzip or Brotli) stacks with minification for even smaller transfers.
  • Minify your styles and scripts too with the CSS minifier and JS minifier.

Edge cases and limitations

  • Optional closing tags are removed, which is valid HTML but can confuse tools that expect every tag to be closed, such as some email builders or XML parsers. Test before using the output there.
  • Whitespace inside <pre> and <textarea> is preserved, since it's meaningful there.
  • Template tags (like {{ }} or <?php ?>) can be altered. Minify the final rendered HTML, not templates.
  • Inline CSS and JavaScript are minified too, so check the page still works.

Frequently asked questions

What does minifying HTML do?

It removes characters that browsers don't need, such as extra spaces, line breaks and comments, making the file smaller.

Can minifying break my page?

Rarely, but whitespace-sensitive content and inline scripts can be affected. Always test the minified version.

Does minified HTML help SEO?

Indirectly. Faster pages improve user experience and Core Web Vitals. Search engines read minified HTML just fine.

How much smaller will my HTML be?

It depends on how much whitespace and how many comments it has. Savings of 10–30% are common for hand-written HTML.

Should I minify HTML that my CMS generates?

Usually a caching or performance plugin does that on the fly. Use this tool for static pages, templates you've already rendered and email HTML.

Related tools

Similar tools

CSS minifier

Minify CSS by removing spaces, line breaks and comments to make stylesheets smaller and pages faster. See the before and after size. Free CSS minifier.

JS minifier

Minify JavaScript by removing whitespace, comments and line breaks to cut file size and speed up your site. See before and after counts. Free JS minifier.

Popular free tools