HTML Minifier

Shrink HTML without changing how the page renders.

Runs in your browser Instant No sign-up
Whitespace
HTML
Minified

Paste, type or drop a file — output appears as you type.

Waiting for input
Processed locally · nothing is uploadedProcessed locally

How to use the HTML minifier

  1. Paste an HTML page or fragment in the left pane.
  2. The minified HTML appears on the right. The status bar shows the size before and after, the gzip size, and how many comments, scripts and styles were processed. The sample shows 835 B → 609 B (−27%) · gzip ≈ 429 B · 1 comment removed · 1 script minified · 1 style minified.
  3. Copy the result or download it as index.min.html.

What it changes, and what it never touches

The minifier reads HTML the way a browser’s tokenizer does, so a > inside a quoted attribute or a </div> inside a JavaScript string can’t confuse it. It then makes only these changes:

  • Comments are removed, except IE conditional comments.
  • Whitespace in text is collapsed: a run of spaces, tabs and newlines becomes one space. Non-breaking spaces (&nbsp; or U+00A0) are not whitespace and stay.
  • Whitespace next to block-level tags (div, p, ul, li, table, headings, section and so on) is removed, because a line starts or ends there and CSS wouldn’t render it. Between inline elements such as a, b, span, img, button and custom elements, one space is kept, because that space is visible.
  • Whitespace before the body (between <head> elements) is removed.
  • Tags are tidied: extra spaces between attributes are removed and </div > becomes </div>. Tag name case is kept, which matters for SVG (foreignObject).
  • Inline <style> and <script> are minified (under More options). Scripts go through Terser, type="module" scripts as modules, and JSON scripts (application/ld+json, importmap) lose their whitespace without touching any value. Templates such as type="text/template" are left alone.

Text inside <pre>, <textarea>, <script> and <style>, every attribute value, and the DOCTYPE are copied unchanged.

Example

<ul class="nav">
  <li><a href="/">Home</a></li>
  <li><a href="/docs/">Docs</a></li>
</ul>
<p>
  Read the <a href="/guide/">guide</a>
  <em>first</em>.
</p>

becomes

<ul class="nav"><li><a href="/">Home</a></li><li><a href="/docs/">Docs</a></li></ul><p>Read the <a href="/guide/">guide</a> <em>first</em>.</p>

The newline between guide</a> and <em> became one space, so the words don’t run together.

Inline-block layouts

If your CSS displays the list items above as inline-block, the whitespace between </li> and <li> was visible as a small gap. Choose Whitespace: Keep one space to keep it:

<ul class="nav"> <li><a href="/">Home</a></li> <li><a href="/docs/">Docs</a></li> </ul>

Warnings

Problems never stop the minifier; it leaves the affected part as it was and tells you where. A script with a syntax error, for example, is copied unchanged with Line 2: Inline <script> left as is: Unexpected token punc «;», expected punc «,» (line 2 of the script). An unclosed comment, tag or <script> is reported the same way.

To minify a standalone script, use the JavaScript Minifier; for a stylesheet, the minify mode of the CSS Formatter. To go the other way and make minified HTML readable, use the HTML Formatter. Most of the savings come from gzip or Brotli on your server, so check the gzip figure rather than the raw size when you compare settings.

Frequently asked questions

Can minifying change how my page looks?

The minifier only removes whitespace that CSS doesn't render with default styles: runs of spaces become one space, and spaces next to block elements such as div, p and li are dropped. One case to know: if your CSS makes list items or divs inline-block, the space between them is visible, and removing it moves them closer together. Choose Keep one space for such pages.

Is whitespace inside pre and textarea kept?

Yes, byte for byte, including the markup nested inside pre. The content of script and style elements is never collapsed either; it is only changed when you minify it with Terser or the CSS minifier.

Are attribute quotes removed?

No. Attribute values are copied exactly as written, quotes and entities included. Only the whitespace between attributes is reduced to a single space. Removing quotes saves very little after gzip and is easy to get wrong.

Which comments are kept?

Internet Explorer conditional comments (<!--[if IE]> … <![endif]-->) and the <!--<![endif]--> closer, because they contain markup. All other comments are removed unless you turn off Remove comments.

Is my HTML uploaded?

No. The minifier runs entirely in your browser.

Last updated