HTML Minifier

Shrink HTML by removing comments and unneeded whitespace. Content of pre elements is kept, and inline style and script blocks are minified as well.

Use the tool

Why this tool exists

Every byte of HTML delays the first paint a little, and templates are usually written with generous indentation and comments for developers. Removing those before deployment makes pages smaller with no change for visitors.

The minifier collapses whitespace between tags, strips comments unless you choose to keep them, and shrinks the CSS and JavaScript inside style and script blocks. Text in pre elements is protected because its spaces are meaningful. It is useful for a static page, an email template, or a snippet you want to embed in a string. Always test the result in a browser, because whitespace between inline elements can affect rendering. The page stays in your browser and is not uploaded.

How to use it

  1. Paste your HTML into the input box.
  2. Tick Keep comments only if you need conditional comments or notes preserved.
  3. Read the compact result in the output.
  4. Copy it and test the page in a browser.

Frequently asked questions

Is the minified page safe to use?

In most cases yes. Whitespace between inline elements, such as two links in a row, can affect spacing, so view the page before deploying. Pre blocks are protected.

Does it rename classes or remove attributes?

No. Tags, attributes and their values are kept. Only comments and whitespace are removed, plus whitespace inside inline CSS and JavaScript.

How is inline JavaScript minified?

Comments and whitespace are removed, and strings, regular expressions and template literals are preserved. Variables are not renamed, so the code stays easy to debug.

How much will it save?

It depends on the source. Heavily indented templates with many comments can shrink considerably. Server compression such as gzip or brotli then reduces the size further.