All tools

CSS minifier

Minify CSS with a standards-aware parser.

CSS minifier
InputCSS

Press Command or Control plus Enter to run. Tab inserts indentation; press Escape, then Tab, to leave the editor.

Result
Your result will appear here.
Ready5 lines · 67 chars

About the CSS minifier

A CSS minifier makes stylesheets smaller by removing comments, whitespace and line breaks and by shortening values where it is safe, for example turning #ffffff into #fff. Smaller CSS downloads faster, which helps pages render sooner.

This minifier uses Lightning CSS, a standards-compliant CSS parser, so it understands modern syntax and keeps your styles working the same way.

How to use the CSS minifier

  1. Paste your CSS into the Input editor, or click Load sample.
  2. Click Minify code or press Ctrl + Enter (Cmd + Enter on Mac).
  3. If there is a syntax error, read the message, fix the CSS and try again.
  4. Click Copy result to copy the minified stylesheet.

Example

Minify a stylesheet

Input

/* Card */
.card {
  margin: 0px 0px 16px 0px;
  color: #ffffff;
  background-color: rgba(0, 0, 0, 0.5);
}

.card:hover {
  transform: translate(0px, -2px);
}

Output

.card{color:#fff;background-color:#00000080;margin:0 0 16px}.card:hover{transform:translateY(-2px)}

Comments go, colors and units get shorter, and values are rewritten in their shortest equivalent form.

Common errors and how to fix them

Unexpected end of input

A { or } has no partner, often an extra } after a rule or a missing one at the end of the file. Count the braces in the last rules of the stylesheet.

Unexpected token Semicolon

The input is SCSS or Less, not CSS: variables like $gap: 8px; and mixins are preprocessor syntax. Compile it to CSS first, then minify the output.

The minified CSS looks different in the browser

Rules may have depended on a browser hack that a minifier treats as invalid. Compare the minified rule with the original and keep the hack in a separate unminified file if you still need it.

Good to know

  • Regular comments are removed. Licence comments that start with /*! are kept.
  • Input is limited to 1 MB, and requests are rate-limited to keep the service fast for everyone.
  • Minification runs on the server, and your CSS isn't stored.
  • For production builds, minify automatically with your bundler and use this tool for quick one-off jobs.

Frequently asked questions

Can minifying break my CSS?

A standards-compliant minifier only makes changes that keep the same meaning. If the CSS is invalid, you'll see an error instead of broken output.

How much smaller will my CSS get?

Typically 15 to 30 percent, depending on how many comments, spaces and long values the original has. Combined with gzip or Brotli compression, the final download is much smaller.

Can I turn minified CSS back into readable code?

You can reformat it, but removed comments and original formatting can't be recovered. Always keep your source files.

How do I minify CSS from the command line?

Use the same engine as this tool: npx lightningcss-cli --minify input.css -o output.min.css. In a project, the bundler usually does it for you; Vite, for example, minifies CSS in production builds.