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.
Paste HTML and get a minified version with comments stripped, whitespace collapsed, and default attributes removed. Live byte-saving stats and one-click copy.
<!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>
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.
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).
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.
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.
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.
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.
Where minifying HTML earns its keep.
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 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.
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.
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.
Habits that keep HTML lean without breaking it.
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.
Server-side compression saves dramatically more bytes than HTML minification on uncompressed payloads. Both layered (minify, then compress) is the right default for production.
If you're embedding example code in <pre>, the minifier won't touch the indentation. Want it tighter? Minify the example yourself before embedding.
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.