Skip to content

CSS Minifier

Paste a stylesheet and get it back on one line with comments and spacing removed, plus the character count before and after.

Runs in your browserFree, no sign-upLast reviewed

Settings

Results update automatically as you type.

Minified CSS

.card{padding:16px;border-radius:12px;color:#101828}

Savings

Before
78 chars
After
52 chars
Saved
33%

Quick answers

What does a CSS minifier remove?
Characters the browser does not need to read the rules: comments, line breaks, indentation, the spaces around braces, colons, semicolons and commas, and the last semicolon in each rule. More aggressive minifiers also shorten colours, drop units from zero values and merge duplicate rules; this one does not.
Does minifying CSS change how a page looks?
It should not, because browsers ignore the whitespace and comments that are removed. With this tool, check three patterns by hand: calc() and clamp() expressions using a plus sign, selectors with a space before a colon, and quoted strings containing spaces around punctuation, since their spacing is altered too.
How much smaller does minified CSS get?
It depends on how the source is formatted. The sample rule on this page, six indented lines with one comment, goes from 78 to 52 characters, a 33% saving. Input that is already compact, such as a{color:red}, saves 0%. Heavily commented and deeply indented files save the most.
Is minifying the same as gzip compression?
No. Minifying rewrites the file so it contains fewer characters. Gzip and Brotli are applied by the web server when the file is sent and are undone by the browser. They work together: a minified file still gets smaller again when the server compresses it.
Can minified CSS be turned back into readable CSS?
The formatting can be restored by a CSS beautifier, which puts each rule and declaration back on its own line. The comments cannot, because they are deleted, so keep the original file.

How CSS Minifier works

This CSS minifier makes four changes: it deletes every /* */ comment, collapses each run of spaces, tabs and line breaks to a single space, removes the space on either side of { } : ; , > ~ and +, and drops the semicolon before each closing brace. Nothing else is rewritten, so colours, units, property order and rule order come out exactly as you wrote them. It is a text-pattern pass, not a full CSS parser, and that has three consequences worth knowing before you ship the output: an addition inside calc() or clamp(), a selector with a space before a pseudo-class, and spacing inside quoted strings are all affected. Each is shown below.

What this minifier changes, with before and after

Every After value is the tool's real output for the Before text.

ChangeBeforeAfter
Spaces and last semicolon in a rulea { color: red; }a{color:red}
Comments, including /*! licence banners/*! licence */ /* note */ body{margin:0}body{margin:0}
Spaces around child and sibling combinators.a > .b + .c ~ .d { margin: 0 auto; }.a>.b+.c~.d{margin:0 auto}
Spaces around commas in a selector list.nav li a , .nav li span { display: block; }.nav li a,.nav li span{display:block}
Spaces inside a media query condition@media (min-width: 600px) and (max-width: 900px) { ... }@media (min-width:600px) and (max-width:900px){...}
Space before !important is kepta { color: red !important ; }a{color:red !important}
Already minified inputa{color:red}a{color:red} (Saved: 0%)

The descendant combinator, the single space in .nav li a, is always kept, because removing it would change which elements match.

Cases to check before using the output

The tool matches characters, not CSS grammar, so it cannot tell when a space or a colon is meaningful. These three patterns come out different from what you wrote.

PatternInputOutputWhy it matters
Addition inside calc(), clamp(), min() or max()height: calc(50% + 10px)height:calc(50%+10px)CSS requires a space on both sides of + in calc(), so the browser discards this declaration. The same happens in clamp(1rem, 2vw + 1rem, 3rem), which becomes clamp(1rem,2vw+1rem,3rem). Subtraction is untouched: calc(100% - 20px) stays as written.
Space before a pseudo-class.list :not(.x) { color: red; }.list:not(.x){color:red}The first targets descendants of .list; the second targets .list itself. The same happens to .card :hover.
Spaces and colons inside a stringcontent: "a : b"content:"a:b"Text inside quotes is treated like any other text, so spacing around : ; , > ~ + { } is removed and double spaces become one.

A fix for the first two: write the addition as a subtraction of a negative, calc(50% - -10px), which is valid CSS and comes out with its spaces intact, and write the selector as .list *:not(.x), which means the same thing and survives minifying.

What it leaves alone that other minifiers shorten

OptimisationExample inputThis tool's output
Shortening hex colourscolor: #ffffffcolor:#ffffff
Dropping units on zero and merging repeated valuesmargin: 0px 0px 0px 0pxmargin:0px 0px 0px 0px
Trimming trailing zeros in numberspadding: 0.50em 10pxpadding:0.50em 10px
Merging rules with the same selector.a { color: red; } .a { color: blue; }.a{color:red}.a{color:blue}
Removing empty rules.b { }.b{}
Removing a doubled semicolon.x{color:red;;}.x{color:red;}
Removing unused selectorsAny rule your HTML never usesKept

Build tools such as cssnano, Lightning CSS and esbuild parse the stylesheet and apply these optimisations safely. Use one of them when a build step is available.

Two complete runs with the Savings figures

The sample rule

/* card */ .card { padding: 16px; border-radius: 12px; color: #101828; } written over six lines

.card{padding:16px;border-radius:12px;color:#101828} Before: 78 chars, After: 52 chars, Saved: 33%

Custom properties, an import and a grouped selector

@import url("a.css"); then :root with --gap: 8px and --font: "Inter", sans-serif; then h1, h2, h3 on separate lines with margin: 0 0 var(--gap) and font-family: var(--font)

@import url("a.css");:root{--gap:8px;--font:"Inter",sans-serif}h1,h2,h3{margin:0 0 var(--gap);font-family:var(--font)} Before: 145 chars, After: 118 chars, Saved: 19%

The semicolon after @import is kept; only a semicolon directly before a closing brace is dropped.

When pasting CSS into a minifier is the right tool

  • A static page, a landing page or a theme with no bundler, where one stylesheet is edited by hand and uploaded.
  • A block of critical CSS that will sit inside a style element in the page head.
  • A custom CSS field in a CMS, email builder or ad platform that limits the number of characters.
  • A quick check of how much of a stylesheet is comments and formatting, using the Saved percentage.

Using CSS Minifier

  1. 1

    Paste your stylesheet into the CSS box, replacing the sample .card rule.

  2. 2

    Read the result under Minified CSS. It updates as you type and there are no options to set.

  3. 3

    Check Savings for the Before and After character counts and the Saved percentage.

  4. 4

    Search your source for calc(, clamp(, min( and max( containing a plus sign and for selectors such as .list :not(.x), and compare those lines in the output (see the table of cases to check).

  5. 5

    Copy the output or download it as style.min.css, and keep your readable file as the one you edit.

Answers to common questions

Does the Saved percentage equal the saving in file size?
Closely, for most stylesheets. The tool counts characters, and a plain ASCII stylesheet uses one byte per character. Files containing non-ASCII characters, in comments or content strings for instance, use more than one byte for those characters, so the byte saving differs slightly.
Are licence comments kept?
No. Every comment is removed, including ones that begin with /*! , which many minifiers preserve. If a library's licence requires its notice to stay in the file, paste the banner back at the top of the minified output.
Does it remove unused CSS?
No. Finding unused rules means comparing the stylesheet with your HTML, templates and scripts. This tool only shortens the text you paste and keeps every rule.
Does it work with SCSS or Less?
It is written for plain CSS. Nested rules will still be compacted, but line comments starting with // are not recognised as comments, so once the line breaks are gone they swallow the code after them. Compile to CSS first, then minify.
Will a source map still work after minifying?
No. The tool does not read or write source maps, and because the output is a single line, an existing map will point at the wrong positions. Generate maps with a build tool if you need them.
Should I keep the unminified file?
Yes. Edit the readable version and treat the minified file as a generated copy. Comments are deleted during minifying and cannot be recovered from the output.
Is my CSS uploaded anywhere?
No. The minifying runs in your browser as JavaScript, so the stylesheet you paste is not sent to a server.

Looking for something else? Browse all developer tools or see every tool.