Looking for a reliable HTML minifier online? Paste any HTML document below and this free tool will strip comments, collapse redundant whitespace, and shrink your markup without breaking layout. Switch to Beautify mode to re-indent minified or tangled source into clean, readable code with a 2-space indent. Content inside pre, textarea, script, and style tags is preserved byte-for-byte so code samples and inline scripts remain intact. Everything runs locally in your browser — no upload, no sign-up, no tracking. See live byte-savings stats the moment you minify so you know exactly how much you shaved off.
HTML is the only resource a browser is guaranteed to need before it can render anything. Every byte you save in HTML lands directly on Largest Contentful Paint (LCP), Time to First Byte (TTFB), and the network bill — there is no "skip this until later" option for the first HTML response the way there is for code-split JS or below-the-fold CSS. Minification is the cheapest performance win available, and yet most teams either skip it (because their bundler does it for them and they never check) or do it badly (with a tool that mangles inline scripts). This guide covers what minification actually does, how it interacts with gzip and Brotli, what it does and does not buy you on Core Web Vitals, and the gotchas that show up in production HTML.
| Operation | Typical bytes saved | Risk |
|---|---|---|
| Strip HTML comments | 1–5% | Conditional comments (<!--[if IE]>) must be preserved. |
| Collapse whitespace between tags | 5–15% | Whitespace between inline elements (links, spans) can be visible. Test before/after. |
| Collapse multiple spaces inside text | 2–5% | Safe outside <pre> and <textarea>. |
| Trim attribute whitespace | <1% | Safe. |
Remove optional closing tags (</li>, </p>) | 2–5% | HTML5-valid but often surprises tools later in the pipeline. |
Remove optional type attributes (type="text/javascript", type="text/css") | <1% | Safe; both are HTML5 defaults. |
Collapse boolean attributes (checked="checked" → checked) | <1% | Safe. |
Combined, minifying typical hand-written HTML cuts 15–35% of bytes. Server-rendered HTML from frameworks already strips most of this, so savings are smaller but still meaningful for SSR pages with developer comments and indentation.
Minification removes structural redundancy (whitespace, comments). Gzip and Brotli remove statistical redundancy (repeated byte sequences). Both layers contribute, and removing one does not replace the other. Real numbers from a typical content-heavy HTML page:
| Pipeline | Bytes | vs raw |
|---|---|---|
| Raw HTML | 120 KB | baseline |
| Minified | 85 KB | −29% |
| Raw + gzip | 22 KB | −82% |
| Minified + gzip | 20 KB | −83% |
| Minified + Brotli | 17 KB | −86% |
The marginal value of minification on top of gzip is small (1–3 KB on a 120 KB page) but real. The big win is on uncompressed responses, on connections without gzip support (rare in 2026), and on the parser-cost side: the browser's HTML parser still has to walk every byte before tokenization, and fewer bytes = less main-thread work.
<img> sooner.Google has confirmed that LCP, INP, and CLS are ranking signals via the Core Web Vitals report in Search Console. The gain from minifying HTML in isolation is typically 50–200 ms on LCP for content-heavy pages — small but cumulatively important when paired with image optimization, font subsetting, and JS code-splitting.
<pre> and <textarea>: whitespace is semantic. Code samples, ASCII art, and form pre-population all break if you collapse it.<script> and <style>: the contents have their own grammar. JavaScript template literals and CSS calc() expressions can both contain whitespace that matters. Minify them with a real JS / CSS minifier if you want; HTML minification is the wrong layer.<!--[if IE]>): still used by some legacy enterprise email rendering. Stripping them is dangerous when you do not control the consumer.{%- tags can corrupt rendering. Minify the rendered HTML, not the template source.<a>A</a> <a>B</a> renders with a space; <a>A</a><a>B</a> does not. Diff the visual output before deploying.<meta name="description"> "to save bytes" is a self-inflicted ranking hit.| Stack | How HTML gets minified |
|---|---|
| Next.js | Built-in via Terser HTML; controlled by next.config.js. |
| Astro | Built-in via astro:compress; on by default in production. |
| Eleventy | Add html-minifier-terser as a transform. |
| Hugo | hugo --minify uses tdewolff/minify in Go. |
| Jekyll | Plugin jekyll-minifier. |
| Webpack / Vite | HTML is usually minified by html-webpack-plugin or vite-plugin-html, both wrapping html-minifier-terser. |
| Cloudflare / Fastly / Akamai | HTML auto-minify is a CDN setting — turn it on for marketing pages, leave it off for SSR app shells (it can race with hydration). |
Search results for "html minifier online", "minify html", and "html beautifier" return many tools but most fail on real-world HTML: they break <pre> code blocks, mangle inline JavaScript, strip semantically-meaningful whitespace inside <textarea>, or upload your source HTML to a server. Here's how the most-used HTML minifiers compare in 2026:
| Tool | Browser-only | Preserves pre/script/style | Beautify direction | Cost |
|---|---|---|---|---|
| FreeDevTool HTML Minifier | Yes | Yes (whitespace-sensitive blocks intact) | Yes | Free |
| htmlminifier.com | Server-side | Configurable | No | Free, ad-funded |
| willpeavy.com/tools/minifier | Server-side | Yes | No | Free |
npm html-minifier-terser | Local install | Full configurability | Yes (separate flag) | Free, OSS |
| Astro / Next.js / Eleventy build minify | Build-time | Yes | N/A | Free (built-in) |
Paste any HTML into the input pane on this page. The minifier runs entirely in the browser — DOMParser parses the input, an AST walker collapses whitespace and strips comments, then serializes the output. Your source HTML never leaves the page. Verify in DevTools Network tab: zero outgoing requests during minify. This matters because production HTML often contains internal API endpoints, customer email patterns, feature-flag remnants, or developer comments that shouldn't be exposed via a third-party minifier service.
| Operation | HTML | CSS | JavaScript |
|---|---|---|---|
| Whitespace removal | Outside whitespace-sensitive blocks | All non-essential | All except in strings/templates |
| Comment removal | <!-- --> | /* */ | // and /* */ |
| Identifier shortening | None safe (would break IDs/refs) | None safe (would break selectors) | Local var renaming (mangling) |
| Dead-code elimination | None (all markup serves output) | Optional (PurgeCSS) | Tree-shaking (esbuild/Rollup) |
| Typical reduction | 10–40% | 20–50% | 30–60% |
| Tool | HTML Minifier | CSS Minifier | JS Minifier |
Decision rule: ALL three should run on production builds. Run them in order: minify CSS first (then inline if small), then minify JS (with tree-shaking), then minify HTML last (which references the minified asset names). Modern build tools (Vite, Next.js, Astro, Eleventy) handle all three automatically.
Pair the HTML minifier with the CSS Minifier and JS Minifier for the full minification trio, the Byte Converter to translate bundle savings to mobile-3G download time, and the DevOps Tools hub for the broader optimization toolkit.
<pre> or <script> blocks — completely untouched.<pre>, <textarea>, <script>, and <style>. This tool leaves those blocks untouched. However, whitespace between inline elements can sometimes matter visually (for example, a space between two adjacent links), so always diff the minified output against the original in a browser before deploying to production. Conditional comments for legacy IE like <!--[if IE]> are also preserved.<script> and <style> blocks verbatim so your inline logic keeps working exactly as written. If you also want to minify those, run the extracted CSS through our CSS Minifier and the JavaScript through our JS Minifier, then paste the results back into your HTML. Splitting the concerns this way gives you safer, more predictable output than a single tool that tries to do everything at once.All tools run in your browser, no signup required, nothing sent to a server.