HTML Minifier

Remove comments and whitespace from HTML while leaving pre, textarea, script and style blocks exactly as they were.

Runs in your browser. Your image is never uploaded.

How to use HTML Minifier — Compress HTML Online Free

  1. 1Paste your HTML into the left-hand box.
  2. 2The minified version appears on the right, with the size saving shown.
  3. 3Copy it, or download it as a file.

About HTML Minifier

HTML carries a lot of bytes that exist purely for the person editing it: indentation showing nesting, blank lines between sections, comments explaining a block. None of it reaches the reader as anything visible, and all of it is transferred on every request.

The risk in minifying HTML is over-reach. Whitespace is not always meaningless — it is significant inside a <pre> block, inside a <textarea>, and between inline elements where it renders as a real space. This minifier parks preformatted regions before touching anything, collapses runs of whitespace rather than deleting them outright, and restores the parked regions afterwards.

Conditional comments survive, because removing one silently changes which stylesheet an old browser loads. Everything else that a parser would discard is discarded.

Frequently asked questions

Will minifying break my page layout?
It should not. Whitespace between tags is collapsed, which browsers already ignore. The one place whitespace does matter — inside <pre> and <textarea> — is left untouched, and so are script and style contents.
Are conditional comments removed?
No. Comments beginning <!--[if are kept, because they are control flow for older Internet Explorer rather than notes. Ordinary comments are removed.
Does it affect inline JavaScript?
No. Everything between <script> and </script> is preserved exactly, including its line breaks, so automatic semicolon insertion cannot change behaviour.
What about spaces between inline elements?
A space between two inline elements is rendered by the browser, so aggressive minifiers can visibly join words. This one collapses runs of whitespace to a single space rather than deleting them, which keeps that spacing intact.
Will it break my code?
For CSS and HTML, no. Only whitespace and comments are removed, and the contents of <pre>, <textarea>, <script> and <style> are preserved exactly as written. If the output ever differs from the input in any way that matters, that is a bug worth reporting.
Why is there no JavaScript minifier?
Because a correct one needs full scope analysis to rename variables safely, and collapsing newlines can silently change behaviour through automatic semicolon insertion — a `return` on its own line means something different once the line break is removed. A half-correct JS minifier hands you broken code, so we do not offer one. Use esbuild or Terser in your build step for that.