CSS Minify — Compress and Shrink CSS Files Online

🔒 Runs in your browser — nothing is sent to a server

CSS minify any pretty-printed or hand-written stylesheet into the smallest valid representation in a single click. Paste a Tailwind utility export, a Bootstrap override, an SVG-icon stylesheet or any CSS blob, and this CSS minifier strips whitespace, removes comments, drops the trailing semicolon in each block, shortens hex colors, drops leading and trailing zeros from numbers, and converts zero-with-length units to a bare 0. License comments (`/*! ... */`), `var(--my-var)`, vendor prefixes and `!important` are preserved untouched. Everything runs 100% inside your browser; your input never leaves your device, nothing is uploaded, logged or sent to any server.

Two-pane view: input and output side by side
Copied!

When to use a CSS minifier online

You reach for a CSS minifier any time a stylesheet is about to travel across a constrained channel: a critical-path CSS extraction inlined into the `<head>`, an above-the-fold theme served on the landing page, a Tailwind purge output ready for a CDN deploy, an SVG sprite bundling its own scoped styles, or a third-party widget injecting CSS into the host page. Browser-local CSS minification means the stylesheet never touches a remote server during the transform — important when the CSS contains unreleased design tokens, white-label brand colors, A/B test variants or admin-only themes you would rather not leak to a SaaS minifier.

How CSS minifying works under the hood

CSS minifying is a two-pass pipeline. The first pass walks the input character by character with a small state machine that tracks whether the cursor is inside a string literal, a `/* … */` comment, a selector, an at-rule prelude or a declaration block. Inside that walk, runs of whitespace collapse to a single space, whitespace adjacent to `{`, `}`, `;`, `,` and the declaration-position `:` is removed entirely, the redundant trailing `;` before `}` is dropped, ordinary comments disappear and license `/*! … */` comments are kept verbatim. The second pass walks the already-compact output token-aware: it lowercases hex colors, shortens `#aabbcc` → `#abc` when each digit pair matches, removes leading zeros from sub-unit decimals (`0.5em` → `.5em`), trims trailing zeros (`1.50rem` → `1.5rem`), and converts zero-with-length-or-percentage to a bare `0` while preserving `0s` and `0ms` because `transition` and `animation` require a time unit. The whole pipeline runs inside the browser, so a multi-thousand-line stylesheet minifies in milliseconds without leaving your tab.

Examples

Input
.card {
  padding: 12px;
  margin: 0px;
  background-color: #FFFFFF;
  border: 1px solid #cccccc;
  border-radius: 0.25rem;
}
.card:hover {
  background-color: #aabbcc;
}
Output
.card{padding:12px;margin:0;background-color:#fff;border:1px solid #ccc;border-radius:.25rem}.card:hover{background-color:#abc}
CSS minify — typical card styles compressed into one line
Input
.hero {
  opacity: 0.85;
  width: 100%;
  height: 100vh;
  margin-top: 0em;
  font-size: 1.50rem;
  transition: opacity 0.3s ease, transform 0ms linear;
}
Output
.hero{opacity:.85;width:100%;height:100vh;margin-top:0;font-size:1.5rem;transition:opacity .3s ease,transform 0ms linear}
Compress CSS — leading and trailing zeros stripped, time units kept
Input
/* normalize spacing — internal note */
/*! Copyright 2026 Acme — MIT */
:root {
  --brand: #ff8800;
  --gap: 16px;
}
.banner {
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  background: var(--brand) !important;
}
Output
/*! Copyright 2026 Acme — MIT */ :root{--brand:#f80;--gap:16px}.banner{-webkit-backdrop-filter:blur(8px);backdrop-filter:blur(8px);background:var(--brand)!important}
CSS minifier — drops `/* … */` but keeps `/*! license */`
Input
.css-minify {
  content: "css minify online";
  font-family: "Inter", sans-serif;
  color: #112233;
  padding: 0.5rem;
}
Output
.css-minify{content:"css minify online";font-family:"Inter",sans-serif;color:#123;padding:.5rem}
Optimize CSS — payload that names the tool itself

FAQ

How do I minify a CSS stylesheet?

Paste the formatted CSS into the input above and click Minify. The CSS minifier strips every newline and run of whitespace between tokens, removes comments, drops the trailing semicolon inside each block, lowercases and shortens hex colors, and converts zero-with-length units to a bare 0. License comments, CSS variables, vendor prefixes and `!important` are preserved exactly as written.

What is CSS minification?

CSS minification rewrites a stylesheet with every byte of optional whitespace, every regular comment and every redundant character removed, while keeping the rendered output identical. Selectors, declarations, specificity and cascade order all stay intact — only the bytes the browser parses change. Minified CSS typically ships 30–60% smaller than its pretty-printed source.

Why should I compress CSS before shipping it to production?

Smaller CSS means a smaller render-blocking payload at first paint, lower CDN egress, faster Time-To-First-Byte on slow networks, and a higher Lighthouse performance score. Browsers apply gzip or Brotli on top of minified CSS, and the two compound — minified-then-gzipped is materially smaller than gzipped-only. The win is biggest on mobile, where every saved kilobyte cuts the parse-and-paint window.

Will the CSS minifier break `var(--my-var)` or vendor prefixes?

No. CSS custom properties (`--brand`, `--gap`), `var(...)` references, vendor prefixes (`-webkit-`, `-moz-`, `-ms-`, `-o-`), `!important` and old-browser hacks (`* html`, `_property`, `*property`) all pass through untouched. The minifier strips inter-token whitespace and known-safe noise; it never rewrites identifiers, never changes specificity and never touches the cascade.

How does the CSS compressor shorten hex colors and numbers?

Six-digit hex colors collapse to three when each pair of digits matches: `#ffffff` → `#fff`, `#aabbcc` → `#abc`. Eight-digit hex with alpha collapses to four under the same rule. Hex is lowercased. Decimal numbers lose leading and trailing zeros: `0.5em` → `.5em`, `1.50rem` → `1.5rem`. Zero with a length or percentage unit becomes a bare `0`, but `0s` and `0ms` are preserved because `transition` and `animation` require a time unit.

How is CSS minify different from CSS beautify?

CSS minify and CSS beautify are exact opposites. Minify strips whitespace, comments and redundant tokens to produce the smallest valid stylesheet for transport. Beautify adds line breaks and indentation back so a human can read and diff the document. The cascade is identical in both directions; only cosmetic whitespace and comment retention differ. Use minify for deploys, beautify for debugging and code review.

Does the CSS optimizer touch CSS Grid, Flexbox or media queries?

No special handling needed — Grid templates, Flexbox declarations and `@media`, `@supports`, `@container` blocks all minify safely. Nested at-rules keep their structure: only the optional whitespace between tokens is removed. Track names, line numbers and column counts inside `grid-template-columns` are preserved exactly because changing their formatting would change the cascade output.

Is it safe to paste a proprietary stylesheet into this CSS minifier online?

Yes — the CSS minifier runs entirely in your browser using a tokenizer written in plain TypeScript. Your stylesheet and the minified output stay on your machine; nothing is uploaded, logged or cached. Safe for unreleased design-system tokens, internal admin themes, white-label brand stylesheets and any CSS you would not want a remote service to retain.

Glossary

CSS (Cascading Style Sheets)

CSS is the W3C-standard language for describing the presentation of HTML and SVG documents — colors, layout, typography, motion. A CSS minifier reduces a stylesheet to its smallest valid byte representation without changing how the browser renders the page. Minification is purely a transport optimization: the parsed cascade is identical before and after.

CSS minifier

A CSS minifier is any tool or function that compresses a stylesheet by stripping inter-token whitespace, removing comments, shortening hex colors, dropping leading/trailing zeros and emitting the smallest valid CSS that still parses to the same rules. Build-time minifiers like cssnano and esbuild do this in CI; a browser-local CSS minifier online keeps proprietary stylesheets off remote servers.

License comment

A license comment is a CSS comment that opens with `/*!` instead of `/*` — for example `/*! Bootstrap v5.3.2 | MIT License */`. The `!` marker is the convention shared by every major minifier (cssnano, terser, UglifyCSS) for "preserve this comment". A correct CSS minifier strips ordinary comments but keeps every license comment so attribution, copyright and SPDX identifiers survive into the production bundle.

CSS custom property (CSS variable)

A CSS custom property — written as `--brand`, `--gap`, `--radius` — is a user-defined value declared inside a selector and read with `var(--name)`. Custom properties cascade and inherit like any other CSS value. A minifier must never rename, remove or rewrite custom properties or their `var()` references because external JavaScript may write or read them by name at runtime.

Shorthand property

`margin`, `padding`, `border-width`, `border-radius` and similar shorthand properties accept one to four space-separated values that map to top/right/bottom/left edges. When opposite or all sides repeat, the four-value form collapses: `10px 10px 10px 10px` → `10px`, `10px 20px 10px 20px` → `10px 20px`. Shorthand optimization is opt-in here because some teams diff these values edge-by-edge and prefer the explicit form.

Vendor prefix

A vendor prefix — `-webkit-`, `-moz-`, `-ms-`, `-o-` — marks a CSS property or value that ships under a browser-engine namespace before becoming standard. `-webkit-backdrop-filter`, `-moz-osx-font-smoothing` and `-ms-overflow-style` are still required for some real-world targets. A safe CSS optimizer leaves every vendor prefix exactly as written; removing them is a fingerprinting decision the build pipeline has to make explicitly.

Related tools