Skip to content
DeveloperRuns in your browser

HTML Minifier

Strip whitespace and comments from HTML to shrink the file.

Input
No upload needed — instant
Privacy
Nothing is uploaded
Cost
Free · no sign-up · no watermark

Loading tool…

The tool is loading its code on your device. This happens once and is cached for later visits.

Processed entirely on your device

Everything you type or paste is handled by JavaScript running in this tab. No request is sent, nothing is logged and nothing is stored. Close the page and it is gone.

Overview

About the HTML Minifier

Minify HTML online — remove indentation, line breaks and comments to cut transfer size, and see the exact byte saving. Everything runs in your browser, nothing is uploaded.

Minification is the last step before HTML meets the network: same document, fewer bytes. It sits at the end of a build for the same reason compilation does — the human-readable source is for people, and the shippable artefact is for machines.

What is removed

Whitespace between tags is the main target: the indentation, the newlines between elements and the runs of spaces that make source readable. HTML comments are dropped too, since they are never rendered. None of this changes what the browser paints, because the rendering engine already collapses inter-element whitespace to a single space.

What must be kept

Whitespace is content in a few places, and removing it there is a real bug:

  • inside pre, where every space and newline is displayed literally;
  • inside textarea, whose value is its raw text;
  • in any element styled with white-space set to pre, pre-wrap or break-spaces;
  • the single space between inline words, which must not be collapsed to nothing.

A minifier that does not understand these contexts will quietly reflow code samples and preformatted blocks. This one leaves them intact.

The compression caveat

If your HTML travels over HTTPS with gzip or Brotli enabled — and it almost certainly does — minification saves less than the raw byte count suggests. Indentation is repetitive, and repetition is exactly what those algorithms compress best. The two together usually beat either alone, but the marginal gain from minifying on top of compression is smaller than the character count implies.

It still matters when the markup is stored uncompressed, embedded in a length-limited field, served over a protocol that cannot compress, or delivered at a volume where a few percent of bandwidth is worth capturing.

Minify at build time, not by hand

The right place for this is a build step that reads your formatted source and writes a compressed artefact. Doing it by hand in an editor means the next person cannot read the file they have to maintain. Keep source pretty, ship it small.

Step by step

How to use the HTML Minifier

  1. Paste the formatted HTML you want to compress.

  2. Press Minify HTML; comments and insignificant whitespace are removed.

  3. Compare the input and output byte counts to see the saving.

  4. Copy the minified markup or download it as an .html file.

Why use it

Benefits and common use cases

What this tool is good for, and what it deliberately does not try to do.

Smaller payloads, faster first paint

Removing indentation and line breaks typically cuts a hand-written template by a third or more before compression, which matters most on large pages and slow connections.

Preserves rendered output

Only whitespace the browser would collapse anyway is removed, and sensitive contexts such as pre and textarea are left intact so the page still looks identical.

Shows the real saving

Reports the character count before and after so you can judge whether minification is worth it for a given document.

Private by design

Unpublished markup and tracking snippets never leave your machine — the minifier is pure client-side JavaScript.

Questions

Frequently asked questions

Short, honest answers about quality, limits and privacy.

Does minifying HTML change how the page looks?

It should not. Whitespace between block elements is collapsed by the browser regardless, so removing it is safe. The exception is pre, textarea and white-space: pre content, where spacing is meaningful — a careful minifier leaves those runs of whitespace alone.

How much smaller does HTML get?

For a hand-indented document, usually 20 to 40 percent. Deeply nested templates with four-space indentation save more. Once gzip or Brotli is applied in transit the extra gain shrinks, because repeated indentation compresses extremely well.

Are comments removed?

Yes. HTML comments are stripped because they are never rendered. Be aware that conditional comments used by very old versions of Internet Explorer would also be removed, so keep them if you still support that path.

Will it remove optional closing tags?

This minifier is deliberately conservative and keeps the document structure intact rather than dropping optional end tags. Aggressive tag removal can break parsers and templating engines, so the whitespace and comment saving is offered without that risk.

Should I minify HTML in source control?

No. Keep the readable, formatted version in your repository and minify as a build step. Minified markup is almost impossible to diff or review, which defeats the purpose of version control.