Skip to content

CSS Minifier & Beautifier

Shrink a stylesheet for production, or turn a minified one back into readable code. Only changes that can't affect rendering are made, and nothing is uploaded.

CSS input0 B
Minified CSS

What the CSS minifier removes

Browsers ignore comments, indentation, line breaks and most spaces in CSS. Removing them makes the file smaller without changing a single rendered pixel:

/* Card component */
.card > .title,
.card > .subtitle {
  color: #333333;
  margin: 0 0 0.5em;
}

→  .card>.title,.card>.subtitle{color:#333;margin:0 0 .5em}

Specifically, the minifier:

  • removes comments, except /*! … */ licence comments if you keep that option on;
  • collapses whitespace and removes spaces around { } ; , > + ~;
  • drops the last semicolon in each block and rules with nothing inside them;
  • shortens six-digit colours that repeat in pairs, so #ffffff becomes #fff;
  • writes 0.5em as .5em.

What it deliberately leaves alone

A minifier that saves a few extra bytes but breaks one layout isn't worth using. These cases are handled carefully:

InputWhy it's kept
calc(100% - 2rem)The spaces around + and - are required inside calc().
a :hoverThe space means “a hovered element inside a link”. Removing it changes the selector.
screen and (min-width: 600px)and( without a space is invalid in a media query.
content: "0.5 #ffffff"Text inside strings is never changed.
.md\:flexEscaped characters in class names, common in Tailwind CSS, stay escaped.
#aabbcc { } as an ID selectorColour shortening only runs on property values, not selectors.
--brand: #FFFFFFCustom property values are left exactly as written.

Build-tool minifiers such as cssnano and Lightning CSS go further: they merge duplicate rules, combine longhand properties into shorthands and drop overridden declarations. Those optimisations are worth having in a build pipeline with tests, but they are also where unexpected visual changes come from.

How much does minifying CSS save?

It depends on how the file was written. Heavily commented, indented source shrinks a lot; CSS generated by a framework is often minified already. Two things matter more for real page speed:

  • Server compression. Brotli or gzip typically shrinks CSS far more than minification does, and the two combine. Check that your server sends Content-Encoding: br or gzip for stylesheets.
  • Unused CSS. Themes and frameworks often ship many times more CSS than a page uses. The Coverage panel in Chrome DevTools shows how much of each file is unused, and Lighthouse reports it as “Reduce unused CSS”.

Because the browser must download and parse CSS before it can render the page, stylesheet size affects how quickly content appears. For the HTML itself, use the HTML Minifier, which also minifies inline <style> blocks.

Minifying CSS in your build

# Lightning CSS (command line)
npx lightningcss --minify styles.css -o styles.min.css

# PostCSS with cssnano
npm install --save-dev postcss cssnano
// postcss.config.js
module.exports = { plugins: [require("cssnano")({ preset: "default" })] };

# Vite, Next.js and most frameworks minify CSS automatically
# in production builds; no extra step is needed.

Use this page for one-off files, theme snippets, email templates and checking what a build tool produced, not as a replacement for minification in your deployment pipeline.

Beautifying minified CSS

Beautify mode does the reverse: one selector per line, one declaration per line, nested rules and media queries indented, and a space after each colon and comma. It is useful for reading a competitor's or a plugin's stylesheet, reviewing a diff, or editing a theme file that was only shipped minified. In the browser, the { } button in the DevTools Sources panel pretty-prints a stylesheet in place.

Frequently asked questions

Can minifying CSS break my site?

Removing comments and whitespace cannot change how a page renders, as long as the minifier respects strings, url() values, escaped characters and the spaces calc() needs. This tool only makes those safe changes. More aggressive optimisations, such as merging rules or rewriting selectors, are where minifiers occasionally break layouts, so this tool does not attempt them.

Does minifying CSS help SEO?

Indirectly. CSS blocks rendering, so a smaller stylesheet can make content appear sooner and improve Largest Contentful Paint, one of Google's Core Web Vitals. Lighthouse also flags unminified CSS. The gain is usually small next to removing unused CSS or serving files with Brotli or gzip compression.

How do I unminify CSS?

Switch to Beautify mode and paste the minified stylesheet. The tool puts each rule and declaration on its own line with consistent indentation. Comments that were removed during minification cannot be recovered.

What is the difference between minifying and compressing CSS?

Minifying rewrites the file itself, removing characters the browser doesn't need. Compression, with gzip or Brotli, is applied by the web server when the file is sent and reversed by the browser. They stack: minify the file, then let the server compress it.

Does this remove unused CSS?

No. Finding unused selectors requires knowing every page and state that uses the stylesheet, which a minifier can't see. Use the Coverage panel in Chrome DevTools to find unused rules, or a build tool such as PurgeCSS that scans your templates.

Is my CSS uploaded anywhere?

No. Minifying and beautifying run in your browser, and the stylesheet never leaves your device.

Related Tools

  • HTML Minifier — Compress HTML, inline CSS and JavaScript to cut file size and speed up your pages, or beautify minified code back to readable form.
  • URL Encoder & Decoder — Percent-encode or decode URLs and query strings with component, full-URL, RFC 3986 or form (+) rules.
  • Base64 Decode & Encode — Decode Base64 to text, images or files and encode text or files to Base64 and data URIs.
  • CSV to JSON Converter — Convert CSV to JSON with delimiter detection, correct handling of quoted fields and leading zeros, and array, keyed-object or JSON Lines output.
  • JSON to CSV Converter — Convert JSON or JSON Lines to CSV with nested-object flattening, array handling, an Excel-friendly UTF-8 BOM and protection against formula injection.
  • Cron Expression Generator — Build and read cron expressions in plain English, see the next 10 run times, and convert between crontab, Spring, Quartz and AWS EventBridge formats.