Skip to content

HTML Minifier

Minify HTML by removing comments and collapsing whitespace.

Processed locally in your browser.

How do you minify HTML?

To minify HTML, comments are removed, whitespace between tags is dropped, and runs of whitespace are collapsed to a single space, while protected blocks (pre, textarea, script and style) are left untouched. This shrinks file size and slightly speeds loading. A 4-line indented snippet with a comment becomes one line like <div class="box"><p>Hello world</p></div>.

Understanding your result

Minifying reduces file size and slightly speeds up loading by removing characters the browser ignores. Because pre and textarea show whitespace, and script and style can depend on it, those blocks are preserved exactly. This tool does not rename classes, inline assets or otherwise rewrite your markup.

Formula and method

Comments are removed, whitespace between tags is dropped and runs of whitespace are collapsed to a single space. Protected blocks (pre, textarea, script, style) are left untouched.

Worked example

A 4-line snippet with a comment and indentation becomes a single line such as <div class="box"><p>Hello world</p></div>.

How to use this tool

  1. Paste your HTML.
  2. See the minified output update instantly.
  3. Copy or download the result.

Common mistakes to avoid

  • Expecting it to validate or fix invalid HTML — it only minifies.
  • Assuming whitespace inside pre or textarea will be collapsed — it is kept.
  • Minifying already-minified HTML and expecting further savings.

About the HTML Minifier

The HTML Minifier shrinks HTML by removing comments and collapsing unnecessary whitespace, while preserving the contents of pre, textarea, script and style so nothing that matters is changed.

Who should use this tool

Web developers and anyone wanting smaller, faster-loading HTML.

Benefits

  • Strips comments and collapses whitespace.
  • Preserves pre, textarea, script and style content.
  • Shows the size saved and lets you copy or download.
  • Private — your HTML never leaves the browser.

Practical use cases

  • Reducing page weight before deploying.
  • Minifying an email or snippet of markup.
  • Cleaning up exported HTML.

Explore all Developer Tools tools

Frequently asked questions

Does minifying change how the page looks?

It should not. Whitespace between tags is ignored by browsers, and whitespace-sensitive blocks like pre and textarea are preserved.

Are scripts and styles affected?

Their contents are preserved exactly. This tool minifies the HTML structure, not the JavaScript or CSS inside.

Is my HTML uploaded?

No. Everything is processed in your browser and nothing is sent to a server.

Share this tool

Free to use — copy the link, share it anywhere, or add the tool to your own website.

Embed this tool on your site (free)

Copy this code and paste it into any web page — it stays free and always up to date: