HTML Minifier

Shrink HTML markup.

Updated
Loading toolโ€ฆ

Shrink HTML markup.

How to use HTML Minifier

  1. Paste your HTML markup into the input box
  2. Run the minifier to strip comments and collapse whitespace
  3. Review the bytes saved, then copy the minified HTML
Try next โ†’CSS MinifierShrink CSS files.

About HTML Minifier

Paste your HTML and this tool shrinks it by removing comments and collapsing the insignificant whitespace between tags. It safely preserves the exact contents of your pre, textarea, script, and style blocks, and keeps IE conditional comments intact so nothing breaks. The moment you paste, you see the original size, the minified size, the bytes saved, and the percentage reduction, then copy the result with one click.

Most people looking for an HTML minifier end up at an npm package like html-minifier or html-minifier-terser, or a command-line build step. This is the no-setup alternative: it runs in the browser, so there is nothing to install and no terminal needed. It works on HTML code from any source, whether that is hand-written markup, a static export, or the output of a PHP or CMS template you have pasted in. One thing to be clear about: it is a whitespace-and-comment minifier, not a JavaScript or CSS minifier. It leaves your inline script and style blocks exactly as they are rather than compressing them the way a terser-based toolchain would, and it does not beautify or reformat markup.

It is completely free with no sign-up, no limits, and no watermarks. Everything happens locally in plain JavaScript, so your markup is never uploaded to a server. Just paste, review the savings, and copy the minified HTML.

Frequently asked questions

Is the HTML minifier free to use?
Yes. It is completely free with no account, no sign-up, and no usage limits. You can minify as much HTML as you want, as often as you like.
Is my HTML uploaded to a server?
No. All minification happens locally in your browser using JavaScript. Your HTML never leaves your device and is never sent, stored, or logged anywhere.
What does this HTML minifier actually do?
It removes HTML comments and collapses insignificant whitespace between tags to reduce file size. It reports your original size, minified size, bytes saved, and the percentage reduction.
Will it break my page's formatting or scripts?
It is a safe basic minifier. It preserves the exact contents of pre, textarea, script, and style elements, and it keeps IE conditional comments, so whitespace-sensitive and executable content stays intact.
Why is there still some whitespace in the output?
To stay safe, the tool keeps a single space where whitespace could be significant, such as between inline elements and around preserved blocks, rather than deleting it. This is a conservative minifier, not an aggressive one.
How is the size saving calculated?
Sizes are measured in real UTF-8 bytes, not just character counts. Bytes saved is original minus minified, and the percentage is that saving divided by the original size.
Does it also minify inline JavaScript and CSS?
No. It preserves the contents of your script and style blocks exactly as written and only compresses the surrounding HTML. If you need your inline JS or CSS shrunk too, run those through a dedicated JavaScript or CSS minifier.
Is this the same as the html-minifier or html-minifier-terser npm package?
It is a browser-based alternative that covers the whitespace and comment removal those packages do. It does not run terser on your inline scripts, so it will not compress embedded JavaScript the way html-minifier-terser can.
Do I need npm or the command line to use this?
No. Unlike npm packages or a build-step minifier, there is nothing to install and no terminal involved. Paste your HTML into the box and the minified result appears instantly.
How does this compare to the Toptal HTML minifier?
It does the same core job of stripping comments and collapsing whitespace to shrink your HTML, and it runs entirely in your browser with nothing uploaded. Exact output can differ slightly because this tool stays deliberately conservative to avoid breaking whitespace-sensitive markup.
Can it beautify or unminify HTML instead?
No. This tool only minifies HTML to make it smaller; it does not format, indent, or expand markup back out. For that you would need a separate HTML beautifier.
Can I minify HTML generated by PHP or a CMS?
Yes. Copy the rendered HTML output from your PHP page, WordPress site, or any other backend and paste it in. The minifier treats it as plain HTML regardless of what produced it.