HTML Minifier

Minify HTML without changing how it renders: comments removed, whitespace collapsed, and pre, textarea, script and style copied through untouched.

Enable JavaScript to customise; default output below.

Nothing is uploaded. The markup stays in this tab.

Live preview page.min.html
<div class="card"><h2>Title</h2><p>Some <em>text</em> here.</p></div>

Output is valid and updates as you type.

Paste markup and get it back smaller, without changing how it renders. Whitespace between inline elements is kept as a single space, and pre, textarea, script and style are copied through byte for byte.

How to use

  1. Paste the HTML. It stays in this tab.
  2. Leave “remove whitespace between block elements” on. That is the whitespace that never renders, so removing it is safe.
  3. Turn it off if you are minifying a fragment whose surroundings you cannot see. Every gap then becomes a single space, which is the most conservative result.
  4. Keep comments only if something reads them: a build step, a template marker, or a licence.
  5. Minify the built output, not the template you edit.

Example

<div class="card">
  <!-- the title -->
  <h2>Title</h2>
  <p>Some <em>text</em> here.</p>
</div>

becomes

<div class="card"><h2>Title</h2><p>Some <em>text</em> here.</p></div>

The space before <em> survives, because deleting it would join two words on screen. The newlines between the block elements do not, because they render as nothing.

Pitfalls

  • Whitespace between inline elements is visible text. <span>a</span> <span>b</span> reads as “a b”; remove the space and it reads “ab”. A minifier that strips all whitespace breaks this every time.
  • pre and textarea show whitespace exactly as written. Both are copied through here without a single character changed.
  • display: inline-block makes whitespace matter in layout too, which is why the four pixel gap between inline-block boxes disappears after minification. That is a change, even if it is usually the one you wanted.
  • Conditional comments are markup, not notes. Removing <!--[if IE]> changes what old browsers see, so those are kept.
  • Some templating systems use comments as markers. Minifying a template rather than its output can quietly remove them.
  • Attribute quotes are left alone. Dropping them is legal in HTML5 and breaks the moment a value contains a space.
  • HTML compresses extremely well. After gzip, the difference between formatted and minified markup is usually a few percent.
  • Minified HTML is much harder to debug in view-source. Keep the readable version as the one you edit.

Compatibility

The output is ordinary HTML5 and renders identically in every browser. No tags are removed, no attributes are rewritten, and no optional closing tags are dropped: those are all legal but change what a parser sees in edge cases. The tool runs entirely in your browser and handles documents up to 100,000 characters.

Frequently asked questions

Will this change how my page looks?
Not if you leave the defaults alone. The only whitespace removed is between block level elements, where it never renders.
Why is there still a space between my tags?
Because removing it would change the rendered text. Whitespace between inline elements is a word gap.
Does it touch my JavaScript or CSS?
No. script and style contents are copied through untouched. Use a CSS or JS minifier for those.
Should I minify WordPress output?
That is what a caching plugin does at the page level. This tool is for markup you are pasting somewhere, such as an email template or a static fragment.
How much smaller does it get?
Typically 10 to 20 percent before compression, and far less after gzip or Brotli.
Weekly drops

New tools, when there are new tools

One email when something worth using ships. No schedule to fill, so no filler.

Your address goes nowhere else, and one click unsubscribes.