Skip to main content
UtilityStack

HTML Minifier — strip the bloat from markup

Paste HTML and get a minified version with comments stripped, whitespace collapsed, and default attributes removed. Live byte-saving stats and one-click copy.

Source: 631Minified: 448183 bytes (29%)
Source HTML
Minified
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Hello world</title><meta name="description" content="An example page used by the HTML minifier demo."><link rel="stylesheet" href="/style.css"></head><body><header><h1>Hello, world!</h1><nav><a href="/">Home</a><a href="/about">About</a></nav></header><main><p> This is an <strong>example</strong> document with <em>plenty of whitespace</em> and a comment. </p></main></body></html>

What this minifier does

It strips HTML comments (except IE conditional comments), collapses whitespace between tags, removes redundant whitespace within text content, and optionally drops default attribute values like type="text/javascript". The contents of <pre>, <textarea>, <script> and <style> are preserved verbatim — minifying them would break their semantics.

Run it on a hand-written HTML file or on the rendered output of a templating engine. Server-side compression (gzip/brotli) handles repeated bytes well, but minified HTML still parses faster, ships less to clients with weak compression, and is the right base before edge caching.

How to use this tool

  1. Paste your HTML into the left pane, or click 'Load sample' to test on an example document.
  2. Toggle the option checkboxes — strip comments, collapse attribute whitespace, remove default attributes — until the output matches what you want.
  3. Click Copy on the right pane to grab the minified HTML. Paste it into your build artifact, your template, or wherever your production HTML lives.

Frequently asked questions

Will it break my page?

Not for standard HTML. The minifier preserves the contents of <pre>, <textarea>, <script> and <style> exactly, and respects HTML's whitespace-collapse rules. Test in your staging environment before flipping production, especially if your template includes whitespace-sensitive constructs (CSS pseudo-elements with content, JS template strings).

What about IE conditional comments?

We keep <!--[if IE]>...<![endif]--> blocks intact. They're rare in 2026 but still occasionally show up in HTML email signatures and old corporate intranets. If your audience definitely doesn't use IE, you can strip them manually.

Does it remove unused attributes?

Only default values (type="text/javascript", method="get", etc.). Removing other attributes would require parsing the document into an AST and understanding which attributes are still referenced — out of scope for a quick lexical minifier.

Can I minify HTML email?

Most clients (Gmail, Apple Mail, Outlook desktop) tolerate minified HTML fine. Some legacy clients (older Outlook for Windows) parse oddly when whitespace between block elements is removed; test before sending to a wide list.

What about source maps?

Source maps are not specified for HTML. If you need to debug minified HTML, run an HTML formatter (Prettier, JSBeautifier) on it locally — most browsers also have a 'pretty print' button in DevTools.

Common use cases

Where minifying HTML earns its keep.

Static-site output

Hugo, Eleventy and Astro emit pretty-printed HTML by default. Run it through this tool before publishing to drop ~15-25% of bytes per page with no template changes.

Email templates

Email rendering tools produce verbose markup. Minifying before sending stays under client size caps (Gmail's 102 KB clip threshold) and keeps the visible body shorter for users.

Inline HTML in JS strings

When a function returns a chunk of HTML as a string, minify it first to keep the JS bundle small. Especially useful for skeleton/placeholder markup that ships in every bundle.

Server-side rendered pages

Run minification as the last step before sending the response. Caches it minified at the CDN edge; humans still see and debug the same DOM in the browser inspector.

Tips and shortcuts

Habits that keep HTML lean without breaking it.

Test the rendered DOM, not the raw HTML

Minified HTML is hard to read but the browser's parsed DOM is identical to the unminified version. Verify visual rendering and DevTools DOM tree, not the raw text diff.

Pair with gzip/brotli

Server-side compression saves dramatically more bytes than HTML minification on uncompressed payloads. Both layered (minify, then compress) is the right default for production.

Keep <pre> contents pre-minified if needed

If you're embedding example code in <pre>, the minifier won't touch the indentation. Want it tighter? Minify the example yourself before embedding.

Don't minify if you're hand-editing

Minified HTML is write-once code. If your team still edits HTML directly, keep the source pretty-printed and run the minifier as a CI step. Mixing the two is a recipe for broken pages.

Ähnliche Tools