Skip to main content
ToolsHub

HTML Minifier

Paste HTML to strip comments and redundant whitespace and shrink the file, with pre, textarea, script and style content preserved — instantly in your browser.

Updated

Files never leave your browser

How to use HTML Minifier

The HTML Minifier shrinks HTML documents by removing the bytes a browser does not need, instantly and entirely in your browser. It strips HTML comments, collapses runs of whitespace between and inside tags, and optionally removes empty attributes, all while carefully preserving the content of pre, textarea, script and style blocks where whitespace is significant. Smaller HTML downloads faster and parses a little quicker, which helps page-load metrics — and because everything runs client-side, you can paste templates or full pages without sending them to any server.

  1. Paste your HTML into the input area.
  2. Toggle which optimisations to apply (comments, whitespace, empty attributes).
  3. Read the minified HTML in the output area.
  4. Check the before and after byte counts.
  5. Copy the minified markup into your project.

Your data never leaves your device — 100% private processing.

What the minifier changes

Minification removes characters that have no effect on how the browser renders a page. The biggest wins usually come from collapsing whitespace: source HTML is often indented for readability, and those spaces, tabs and newlines between tags are insignificant in normal flow content. The minifier replaces each run with a single space, or removes it entirely between block-level tags. Comments are stripped unless they are conditional comments (the old <!--[if IE]> syntax), which some legacy targets still rely on. Empty attributes such as class="" or style="" can optionally be dropped because they carry no information. Crucially, none of this touches the inside of pre, textarea, script or style elements, where every space and newline can be meaningful — those regions are stashed before processing and restored afterwards untouched.

Optimisations applied
OptionEffect
Remove commentsDeletes <!-- --> blocks (keeps conditional comments)
Collapse whitespaceReduces runs of spaces/newlines to one space
Remove empty attributesDrops class="", id="", style="" and similar
Preserve blocksLeaves pre, textarea, script, style untouched

Minification, gzip and real-world gains

It is fair to ask how much minification helps when servers already compress responses with gzip or brotli. Compression is very good at squeezing repetitive whitespace, so the saving from minified HTML after compression is smaller than the raw byte difference suggests — but it is rarely zero, because minification also removes comments and redundant structure that compression cannot infer away. More importantly, smaller HTML means less work for the browser to parse and less memory to hold the document, which matters on low-end devices. Treat HTML minification as one cheap optimisation among many: combine it with compression, caching and minified CSS and JavaScript rather than relying on any single technique. Because this tool is a quick paste-and-copy utility, it is ideal for one-off cleanups; for production sites, wire an equivalent step into your build pipeline so every deploy benefits automatically.

Worked examples

Strip comments

Inputs: <!-- nav --> <nav> … </nav>

Result: <nav> … </nav>

Collapse whitespace

Inputs: <p> hi </p>

Result: <p> hi </p>

Glossary

Minification
Removing characters that do not affect output to reduce file size.
Whitespace collapsing
Replacing runs of spaces, tabs and newlines with a single space.
Conditional comment
A legacy <!--[if IE]> comment that some old browsers interpret as markup.
Significant whitespace
Spaces and newlines that affect rendering, as inside a pre or textarea element.
Empty attribute
An attribute with no value, such as class="", that can be safely removed.

Related reading

Frequently Asked Questions

Free · No spam

Get weekly tool tips & updates

New tools, power-user tips, and productivity hacks — delivered free every Friday.

No spam, ever. Unsubscribe with one click.

Why use HTML Minifier?

  • Removes comments and collapses redundant whitespace
  • Preserves pre, textarea, script and style content exactly
  • Optional removal of empty class, id, style and similar attributes
  • Reports the byte savings so you can see the impact
  • Runs client-side — your markup never leaves the browser

Common use cases

  • Trim template output before shipping a static page
  • Reduce inline HTML size in emails or embedded snippets
  • Clean up exported or generated markup before committing
  • Compare original and minified size to justify a build step
  • Quickly strip comments from a page before sharing it

Related Developer Tools

Explore all Developer Tools.