Skip to content

CSS Minifier

Compress and minify CSS code online to reduce file size. Remove whitespace, comments, and shorten selectors for faster page loads.

0 characters
Minified CSS will appear here...

About CSS Minifier

This CSS Minifier removes comments, whitespace, and unnecessary characters from your stylesheets. Minified CSS files load faster, reducing page load times and improving Core Web Vitals scores.

How to Use CSS Minifier

1

Paste or upload CSS

Paste your formatted CSS into the input editor, or click Upload to pick a .css file. Full stylesheets, fragments, and individual rules all work.

2

View minified output

The minified CSS appears instantly in the output panel — all unnecessary whitespace removed, comments stripped, redundant characters eliminated. Functionally identical to your input but in fewer bytes.

3

Check the savings

Below the output, the Saved % stat shows your exact size reduction. Most formatted CSS saves 20-40%; heavily commented or deeply indented files save 50%+.

4

Copy or download

Click Copy to use the minified CSS elsewhere, or Download as a .css file. Drop it into your production build, inline it into HTML, or use as a CDN asset to reduce bandwidth.

When to Use CSS Minifier

Reducing render-blocking stylesheet size

CSS is render-blocking — browsers must download and parse it before painting. Minifying production CSS shaves 20-40% off file size, directly improving Time-to-First-Paint and Largest Contentful Paint (LCP). For high-traffic pages, that's measurable performance and Core Web Vitals improvements.

Inlining critical CSS in <head>

Above-the-fold critical CSS is often inlined into <style> tags in the document head to eliminate render-blocking external requests. Minifying first keeps the head section as small as possible — every byte in the head delays first paint, so compactness matters more here than anywhere else.

Email styles and AMP CSS

Email clients limit total message size, and AMP imposes strict CSS size caps (75 KB inline). Minifying CSS keeps you under these limits while still allowing rich design. Without minification, complex email templates frequently get clipped by Gmail or rejected by AMP validators.

Embedding CSS in JavaScript bundles

Build tools that inline CSS into JS bundles (CSS-in-JS, styled-components production builds, single-file SPAs) benefit from pre-minified CSS strings — smaller bundle sizes, faster parse, less memory pressure. Minify before stringification for maximum effect.

CSS Minifier Examples

Beautified to minified CSS

Input
.btn {
  padding: 0.5rem 1rem;
  background: #3b82f6;
  color: white;
  border-radius: 0.375rem;
}

.btn:hover {
  background: #2563eb;
}
Output
.btn{padding:.5rem 1rem;background:#3b82f6;color:white;border-radius:.375rem}.btn:hover{background:#2563eb}

The 10-line beautified CSS (180 chars including indentation) becomes a single line (108 chars) — a 40% reduction. Notice '0.5rem' becomes '.5rem' (leading zero removed). All semantic content is preserved; only whitespace and the trailing semicolon before } are stripped.

Removing CSS comments

Input
/* Primary button */
.btn {
  /* Adjust padding */
  padding: 0.5rem 1rem;
  background: #3b82f6;
}
Output
.btn{padding:.5rem 1rem;background:#3b82f6}

Standard CSS comments are removed since they don't affect rendering. The 96-character commented version becomes 43 characters — 55% reduction. License comments marked with /*! ... */ are typically preserved by minifiers to retain copyright notices.

Preserving CSS variables and calc()

Input
:root {
  --primary: #3b82f6;
  --spacing: 1rem;
}

.card {
  padding: calc(var(--spacing) * 2);
  background-color: var(--primary);
}
Output
:root{--primary:#3b82f6;--spacing:1rem}.card{padding:calc(var(--spacing) * 2);background-color:var(--primary)}

CSS custom properties (--primary, --spacing) and var() references are preserved exactly. The calc() expression keeps its internal whitespace (some browsers require it for correct parsing). The multi-rule structure is collapsed but the cascade and specificity are unchanged.

Tips & Best Practices for CSS Minifier

  • 1.Pair CSS minification with HTTP compression (gzip or brotli) for maximum effect. Minified + gzipped CSS is typically 70-85% smaller than formatted uncompressed CSS — much more than either alone.
  • 2.Don't minify CSS during development. Keep your source in version control formatted for diffs and code reviews; minify only at build time. Most modern build tools (webpack with css-loader, vite, parcel, esbuild) do this automatically.
  • 3.Watch the Saved % stat: anything below 10% means your input was already nearly minified. Additional savings come from gzip at the transport layer, not character removal.
  • 4.If you use CSS Modules or CSS-in-JS, the output is already minified by your bundler in production. Use this tool for handwritten CSS, design system tokens, or third-party CSS you're modifying.
  • 5.Minified CSS is hard to debug in production. Use source maps (most build tools generate them automatically) so DevTools can show the original formatted source while the browser uses the minified version.
  • 6.For maximum minification, also enable advanced optimizations in your build (cssnano with preset 'advanced'): merging duplicate rules, shortening color names, removing unused selectors. These transformations require careful testing but can shave additional 5-15% off output size.

Frequently Asked Questions

A CSS minifier removes all unnecessary whitespace, line breaks, comments, and redundant characters from CSS, producing the smallest possible valid stylesheet. The result is functionally identical CSS that's typically 20-40% smaller — meaningful at scale where stylesheet size affects page load performance.