Skip to content

HTML Minifier

Shrink your HTML with a conservative minifier that leaves <pre>, <textarea> and <script> content untouched.

Processed locally in your browser

Options
0 chars · 0 lines
The result will appear here.

What is HTML Minifier?

Minifying HTML removes bytes that browsers do not need: comments and the indentation and line breaks between tags. Smaller documents download and parse faster, which matters for landing pages and e-mail templates.

This minifier is deliberately safe. It removes comments (optionally keeping IE conditional comments), collapses runs of whitespace into a single space and drops it next to block-level tags, but leaves the content of <pre>, <textarea>, <script> and <style> as written. An option also removes whitespace and comments from inline CSS. The result shows the size before and after.

How does it work?

  1. Paste your HTML into the input box.
  2. Choose whether to remove comments, keep IE conditional comments and collapse whitespace.
  3. Optionally enable inline CSS minification for <style> blocks and style attributes.
  4. Check the size saved, then copy or download the minified HTML.

Common use cases

  • Reducing the weight of a static landing page or an HTML e-mail.
  • Inlining a small HTML snippet in a JavaScript string or a data URL.
  • Stripping developer comments before publishing a template.
  • Estimating how much whitespace a page carries before setting up a build step.

Examples

Try this input in the tool above:

Input
<!DOCTYPE html>
<html>
  <head>
    <!-- page title -->
    <title>Demo</title>
    <style>
      body { margin: 0; /* reset */ }
      p    { color: #333; }
    </style>
  </head>
  <body>
    <!--[if IE]><p>Old browser</p><![endif]-->
    <h1>  Hello   <em>world</em>  </h1>
    <pre>  keep
    this   spacing </pre>
  </body>
</html>
Output
<!DOCTYPE html><html><head><title>Demo</title><style>
      body { margin: 0; /* reset */ }
      p    { color: #333; }
    </style></head><body><!--[if IE]><p>Old browser</p><![endif]--><h1>Hello <em>world</em></h1><pre>  keep
    this   spacing </pre></body></html>

Privacy

HTML Minifier runs entirely in your browser. The text or files you provide are processed on your device and are not uploaded, logged or stored on our servers.

Limitations

It does not rewrite attributes or quotes, remove optional tags, or minify JavaScript, so savings are smaller than aggressive minifiers, and a single space between inline elements is intentionally kept.

Frequently asked questions

Will minifying break my page?

The rules are conservative: preformatted text, textareas, scripts and styles are left as they are. Whitespace between inline elements is reduced to one space, not removed, so words do not run together.

What happens to conditional comments?

With "keep IE conditional comments" on, comments such as <!--[if IE]>…<![endif]--> are preserved, because browsers act on them. Turn it off to remove them too.

Does it minify JavaScript?

No. Script content is copied unchanged. Use a dedicated JavaScript minifier in your build if you need that.

More tools in Developer Tools →