HTML/CSS Minifier

Strip comments and collapse whitespace from HTML or CSS to shrink it before you ship — pre, script, style, and textarea content stays byte-for-byte intact. Runs entirely in your browser; nothing is uploaded.

How this minifier works

The HTML mode strips comments (except IE conditional comments), then collapses every run of whitespace outside <pre>, <textarea>, <script>, and <style> tags down to a single space and trims the ends — those four tags' contents are carved out first and pasted back untouched, since whitespace inside them can be visible text or syntactically significant code. The CSS mode strips /* */ comments, removes whitespace around { } : ; ,, drops the redundant semicolon before a closing brace, and removes empty rule blocks — while protecting url(...) values and quoted strings from having their internal whitespace collapsed. Byte sizes are measured with the same UTF-8 encoding a real HTTP response uses, not plain character counts, so the savings percentage is accurate for non-ASCII content too. Everything runs in your browser; nothing you paste is sent to a server.

When minifying is worth it

Minify what the browser must download before it can draw the page: the HTML document and any CSS in the head. Hand-written or CMS-generated markup is full of indentation and comments that cost bytes on every visit. If your site already goes through a build step that minifies for production (most modern frameworks do), you will see little gain here; the tool is most useful for hand-edited pages, email templates, CSS snippets pasted into a CMS, and one-off pages with no build pipeline.

A small example

The CSS below is 81 bytes before minifying and 52 bytes after, roughly a 36% saving:

/* buttons */
.btn {
  color: #fff;
  background: #0a66c2;
  padding: 8px 16px;
}
.btn{color:#fff;background:#0a66c2;padding:8px 16px}

What minifying will not do

It does not rename classes, merge rules, remove unused CSS or reorder anything, so the page renders exactly as before. The bigger speed wins are usually elsewhere: oversized images, render-blocking scripts and slow server responses. Run the Page Speed Check or the Core Web Vitals Checker to see what is actually slowing a page, and read Core Web Vitals explained for what the numbers mean.

Frequently asked questions

Will minifying break my HTML or CSS?

No — this tool only removes what browsers ignore anyway: comments and redundant whitespace. It never touches the content of <pre>, <textarea>, <script>, or <style> tags, so preformatted text, inline JavaScript, and inline CSS survive exactly as typed. CSS string literals and url(...) values are protected the same way, so a space-sensitive value like a data URI or a quoted string is never touched.

Why not just remove all whitespace?

Between two inline elements, whitespace is sometimes the only thing separating two words visually — deleting it entirely could glue "Hello" and "World" together as "HelloWorld". Collapsing runs of whitespace down to a single space is what real minifiers do for exactly this reason: it shrinks the file without changing how the page renders.

Are IE conditional comments removed?

No. Comments that start with <!--[if are left completely untouched, including their internal markup and whitespace, because old Internet Explorer versions parse them as real conditional logic rather than as comments. A generic minifier that strips every HTML comment would silently break any page still shipping IE fallbacks.

Does this run on a server?

No — everything happens in your browser with plain JavaScript. Nothing you paste here is uploaded anywhere, which makes it safe to use on unreleased markup, client work, or anything else you'd rather not send to a third-party service.

How much size does minifying actually save?

It depends entirely on how the source was formatted. Hand-written, heavily indented HTML or CSS with lots of comments can shrink by 20-40%; already-compact output from a build tool might only drop a few percent. The stats line under the output shows the exact before/after byte counts for whatever you pasted.

Does minifying HTML and CSS help SEO?

Indirectly. Smaller files download and parse faster, which helps load metrics such as Largest Contentful Paint, and speed is a light ranking signal. Minifying alone will not move rankings, but it is a cheap part of a speed fix, and it matters most for render-blocking CSS in the page head.

Is minifying the same as gzip or Brotli compression?

No, they stack. Minifying rewrites the source to be shorter. Gzip or Brotli then compress the bytes your server sends. A minified file still compresses well, so use both: minify at build time and turn on compression on the server. You can confirm compression is on with the HTTP Header Checker, which shows the Content-Encoding header.

Should I minify JavaScript here too?

This tool handles HTML and CSS only. JavaScript needs a real parser to shorten safely, so use your build tool's minifier (esbuild, Terser or your framework's production build) rather than whitespace stripping.

Can I turn the minified output back into readable code?

Not exactly. Comments are gone for good, and the original indentation is not stored. Keep your readable source in version control and treat the minified copy as a build output. If you only need to read someone else's minified CSS, paste it into any formatter or your browser's developer tools.

Read next

Related tools

We use cookies to analyze site usage and improve your experience. You can decline non-essential cookies. Privacy Policy