HTML Formatterhtmlformatteronline.com

HTML minifier

Strip whitespace, line breaks and comments to shrink an HTML file before it goes to production. The size readout tells you how much you saved.

Your HTML 0 lines
Minify
Minified 0 lines
Paste HTML on the left, then press the button.

Minification, honestly

Minifying HTML is worth doing and rarely worth agonising over. Here is what it removes, how much it really saves once compression is in play, and the one edge case that catches people out.

What gets removed

Minifying is a set of safe deletions. This tool applies these:

  • Whitespace between tags. Newlines and indentation that exist purely for readability.
  • Runs of whitespace inside text. Collapsed to a single space, which is what the browser renders anyway.
  • Comments. Removed unless you tick Keep comments. Conditional comments for old Internet Explorer are the one case where keeping them matters, and almost nobody needs that any more.
  • Leading and trailing whitespace around <script> and <style> contents.

It does not touch attribute values, does not strip quotes, does not remove optional closing tags, and does not reorder anything. Those extra tricks buy a few more bytes and introduce real risk.

How much you actually save

For a typical hand-written page, minifying HTML removes somewhere between 10 and 30 percent of the raw bytes. That number sounds better than it is, because your server almost certainly compresses responses before sending them, and compression already handles repeated whitespace extremely well.

StageTypical pageSaving vs raw
Formatted HTML48 KB—
Minified HTML36 KB25%
Formatted + gzip9.1 KB81%
Minified + gzip8.4 KB83%

Illustrative figures, but the shape holds: compression does most of the work, and minification adds a small amount on top. Worth doing in a build step where it is free. Not worth hand-editing files over.

The one thing that will bite you

Whitespace between inline elements is not always insignificant. Browsers render a single space where a newline separates two inline elements. If your layout was built assuming that space exists — inline-block grids are the classic case — minifying removes it and your items shift.

The fix is not to avoid minifying. It is to stop relying on that space: use flexbox or grid for layout, or set font-size: 0 on the container. Either way, check a minified page in the browser before you ship it.

Where minification belongs

In your build pipeline, not in your editor. Keep your source files formatted so they are readable and produce clean diffs, and let the build produce the compressed version. Every static site generator and bundler worth using has an HTML minifier available as a plugin.

This page is for the times when you do not have a pipeline: a single landing page, an email template, an HTML snippet going into a CMS field with a size limit, or a quick check on how much a file would shrink.

Questions about this tool

Does minified HTML hurt SEO?

No. Search engines parse HTML the same way browsers do and are indifferent to whitespace. The indirect effect is on page speed, which is a ranking signal — but as the table above shows, compression matters far more than minification does.

Can I un-minify later?

Yes. Switch to Beautify and the indentation comes back. What does not come back are comments, if you let it strip them. Keep your source file.

Does it minify the CSS and JavaScript inside the page?

No. It trims whitespace at the edges of those blocks but does not touch the code itself. Minifying JavaScript safely requires a JavaScript parser — use a dedicated tool for that, or a bundler.

Should I minify HTML emails?

Carefully. Email clients are much less forgiving than browsers, and some — Gmail in particular — clip messages over about 102 KB, so shaving bytes genuinely helps. But nested-table layouts are exactly the kind that depend on inline whitespace. Minify, then send yourself a test.

Related tools

Learn the why, not just the how

Longer reading on formatting, indentation and minification.