1. Home
  2. Coding Tools
  3. HTML Minifier

HTML Minifier

Reduce HTML file size by removing comments, line breaks and extra whitespace while preserving pre, textarea, script and style content.

Runs locally in your browser. Your files and data are never uploaded or stored.

About the HTML Minifier

The HTML Minifier shrinks your HTML documents by removing comments, collapsing runs of whitespace and stripping spaces between tags. The result is a smaller page that downloads faster, which helps most on landing pages, email templates and static sites.

The minifier is careful: the contents of <pre>, <textarea>, <script> and <style> blocks are preserved, and conditional comments for old email clients are kept. For the smallest output, minify inline CSS and JavaScript separately with our CSS Minifier and JavaScript Minifier.

What minification removes, with an example

Here is a short piece of HTML as you might write it:

<!-- Main menu -->
<nav class="menu">
    <a href="/">Home</a>
    <a href="/blog/">Blog</a>
</nav>

After minification the comment and the line breaks are gone:

<nav class="menu"><a href="/">Home</a><a href="/blog/">Blog</a></nav>

On a single small page the saving is modest, but on long templates with many comments and deep indentation it is often 10–20% of the file size.

Good to know before you minify

  • Keep the original. Minified HTML is meant for publishing, not editing. Save the readable version for future changes.
  • Check inline elements. The minifier removes whitespace between tags, so in the example above the two links now touch each other. If your design relies on that space (links in a sentence, inline buttons), add the gap with CSS margin or keep a &nbsp;, and preview important pages after minifying.
  • Server compression still matters. Gzip or Brotli on your hosting shrinks files much more. Minify and compress together for the best result.

How to use the HTML Minifier

  1. Paste your HTML into the input box.
  2. Choose whether to remove comments.
  3. Click Minify HTML.
  4. Copy the minified HTML.

Frequently asked questions

Can minifying HTML change the layout?

Removing whitespace between inline elements (like links or inline-block buttons) can remove small gaps. Check the result visually if your layout depends on those spaces.

Is whitespace inside pre tags kept?

Yes. Content inside pre and textarea elements is preserved exactly.

Does it minify inline CSS and JS?

It trims them but does not fully compress them. Use the dedicated CSS and JavaScript minifiers for that.