Skip to content

HTML Minifier

Paste HTML and get unnecessary whitespace and comments stripped for a leaner payload. Optionally minify embedded <style> and <script> blocks too, collapsing every kilobyte you ship to the browser without touching your source.

  • Collapses whitespace and removes HTML comments
  • Optionally minifies inline <style> blocks (CSS)
  • Optionally minifies inline <script> blocks (JS via terser)
  • Preserves whitespace in <pre>, <code>, <textarea> and SVG
  • Configurable — toggle CSS/JS minification independently
  • Runs fully client-side via html-minifier-terser

Minifier

Your HTML never leaves the browser

How to minify HTML

  1. 01

    Paste the HTML

    A full page, a template fragment, or a single element — all work.

  2. 02

    Choose which extras to enable

    Toggle inline CSS minification and/or JS (terser) minification on or off depending on how aggressive you need the compression.

  3. 03

    Copy the result

    The minified HTML updates as you type and can be copied in one click.

Why minify HTML — it is not just about bandwidth#

Every space, tab, newline and comment in your HTML is bytes the browser must download, parse, and discard. On a fast connection that overhead is invisible; on a mobile network — especially with a few hundred kilobytes of HTML across a page and its deferred fragments — those wasted bytes add real latency. Minification removes only the characters that have zero effect on rendering: extra whitespace between tags, comments the author left for themselves but the user never sees, and optional closing tags the spec allows you to omit.

But the bigger savings often come from compressing what lives inside the HTML, not the markup itself. Inline <style> blocks and <script> blocks carry CSS rules and JavaScript that, in many real-world pages, account for 40 – 60 % of the total HTML footprint. Minifying them as part of the same pass — applying the same whitespace removal that the outer markup gets, plus CSS property compression and JS identifier shortening — doubles the effective compression rate without adding a separate build step.

Google and other search engines factor page speed into ranking. While minification alone will not replace a proper build pipeline, it is a quick, measurable win for performance audits — especially on pages that ship third-party embed snippets or CMS-rendered HTML that was never designed to be lean.

How much can you really save?#

The answer depends entirely on how the HTML was written. A hand-crafted page where the author already collapsed whitespace and kept comments sparse may lose only 5 – 10 % of its size. A page dumped from a CMS that indents every level of nesting with four spaces and carries verbose copyright banners in <!-- --> comments can lose 30 – 50 % of its raw byte count before gzip — sometimes more, because gzip cannot compress repeated whitespace as efficiently as it compresses repeated content.

Inline CSS and JS multiply the savings. A typical <style> block of a few dozen rules loses about half its size when whitespace is collapsed and shorthand properties are compressed (a margin: 2px 2px 2px 2px becomes margin:2px, for instance). An inline <script> carrying a few kilobytes of JS — common in analytics snippets, tracking scripts, and embed code — shrinks by roughly the same margin when unnecessary spaces are stripped.

To give a concrete real-world example: a default WordPress post with Gutenberg blocks, a theme stylesheet inlined by a performance plugin, and a standard analytics snippet typically ships 45 – 70 KB of raw HTML. After full minification with CSS and JS compression enabled, that drops to 15 – 25 KB — a saving of 60 – 70 % before any gzip or Brotli compression the server applies on top.

When — and where — to be careful#

Not every whitespace character in HTML is optional. The <pre> element, <code>, <textarea>, and SVG <text> elements rely on exact whitespace for their rendered output — collapse the spaces inside them and the page visibly changes. This tool deliberately skips those elements.

Comments are another boundary. <!--[if ...]><![endif]--> conditional comments that older Internet Explorer versions need are real comments in HTML syntax, but removing them would break IE-specific layout for the small fraction of users still on those browsers. This tool removes all HTML comments by default — if your template targets IE with conditional comments, you should leave JS minification on but verify the output manually the first time.

Inline CSS and JS minification each carry their own subtle rules. CSS minification must preserve spaces inside calc() around + and - operators (the CSS spec requires them), preserve the content of url() and quoted strings exactly, and avoid collapsing zero-values in ways that change which property applies. JS minification via terser is the same engine Webpack and Rollup use — it shortens local variable names, strips whitespace, and removes dead code — but it does not understand your runtime environment, so it will not tree-shake across separate <script> blocks. Enable JS minification for payload reduction, not for dead-code elimination.

When minification is enough — and when it is not#

For a simple HTML page served from a basic web host, minification paired with gzip (which nearly every server enables by default) is often the only optimisation you need. The combination of removing redundant bytes and then compressing the rest usually lands well within Core Web Vitals thresholds for most content.

For a modern single-page app or a site with hundreds of kilobytes of JS, minification is table stakes — you also want bundling (to deduplicate dependencies across files), tree-shaking (to drop unused exports), code splitting (to defer code the first page does not need), and Brotli compression (which beats gzip by another 15 – 25 % on HTML). Those are build-tool concerns, not the job of an online minifier. What this tool gives you is a quick way to make any HTML snippet — a CMS template, a cached fragment, an email — as small as it can be, without setting up a build pipeline.

Frequently asked questions

What exactly does the HTML minifier strip?

It collapses runs of whitespace between tags to a single space, removes all HTML comments (including conditional comments), strips optional quotes in attributes where the HTML spec permits, removes boolean attribute values, and normalises DOCTYPE to the shortest valid form.

Does it break <pre>, <code>, or SVG content?

No. Whitespace inside <pre>, <code>, <textarea>, and SVG <text> elements is preserved exactly as written, because those elements render whitespace as part of their content.

Can I minify inline CSS and JS separately?

Yes — the tool provides independent toggles for inline <style> CSS minification and inline <script> JS minification (via terser). You can enable one, both, or neither depending on your needs.

Which HTML minifier does this tool use under the hood?

It uses html-minifier-terser, the actively maintained fork of kangax/html-minifier that supports ES6+ JavaScript via terser. It is the same library used by build tools like html-webpack-plugin.

Does minification affect SEO or search rankings?

Not directly — minified HTML is functionally identical to the original, and search engines index the rendered content, not the source. However, faster page load times (from smaller payloads) are a known ranking signal, so minification can indirectly help SEO by improving Core Web Vitals like Largest Contentful Paint.

Will this tool minify external CSS or JS files referenced via <link> or <script src>?

No — only inline <style> and <script> blocks (content embedded directly in the HTML) are affected. External files referenced by src or href attributes are left untouched. Minifying those requires a build tool that can follow the dependency graph.

Is my HTML sent to a server?

No. Everything runs in your browser — the HTML you paste never leaves your machine.

Can I reverse the minification later?

This tool does not include a beautifier / formatter — minification is a one-way operation that discards information (comments, optional whitespace) that cannot be recovered. Always keep a copy of your original source if you might need to edit the HTML later.

Developers

UUID Generator

Generate cryptographically random UUID v4 or time-ordered UUID v7, in bulk.

Developers

Base64 Encoder & Decoder

Encode and decode Base64 with correct UTF-8 handling, including the URL-safe alphabet.

Developers

ULID Generator

Generate ULIDs — sortable by creation time like UUID v7, but Crockford Base32 instead of hex.