About the CSS Minifier
Stylesheets load before a page can be drawn, so trimming them helps pages appear faster. This CSS minifier removes comments, unnecessary whitespace, the last semicolon in each block and leading zeros in values such as 0.5em, while keeping the spaces that calc() expressions and custom properties need to work. It reports the original and minified sizes. Always keep the readable source file for editing, and minify a copy for publishing, since minified CSS is hard to change by hand later. To expand minified CSS again, use the CSS Formatter, and for scripts, the JavaScript Minifier.
A few optional passes squeeze out extra bytes. A six-digit hex colour whose pairs repeat, such as #ffcc00, can be written as #fc0. A zero length does not need a unit, because 0px and 0 mean the same thing. And empty rule blocks, usually left behind when the last declaration in them was deleted, can be dropped completely. Each pass can be switched on or off.
Nothing here changes what the stylesheet does. Rules are never merged, properties are never reordered and selectors are never combined, because all three interact with the cascade and can quietly change which declaration wins. A handful of saved bytes would never justify a page whose layout breaks somewhere you forgot to test, so the tool sticks to edits that are provably safe.
How to use the CSS Minifier
- Paste the stylesheetA complete file or a small fragment both work.
- Pick the extra passesDecide whether to shorten hex colours, remove units after zero and delete empty rules.
- Run MinifyThe compressed CSS is shown together with the old size, the new size and the saving.
- Take the outputCopy it to the clipboard or save it as a file.
CSS Minifier features
- Comments and surplus whitespace removed
- The semicolon before each closing brace dropped
- Six-digit hex colours shortened when the pairs repeat
- Units removed from zero values
- Empty rule blocks deleted
- Rules never merged or reordered, so the cascade stays as written
- Original size, minified size and percentage saved
Common uses
- Trimming a stylesheet just before it goes live
- Making critical CSS small enough to inline in the page head
- Cutting the weight of the styles inside an email template
- Finding out how much of a file is comments and spacing
- Compressing a stylesheet that has been edited by hand for years
Minifying CSS in practice: a real stylesheet measured, render-blocking styles, critical CSS, unused rules, calc spacing and caching
Every stylesheet in the page head blocks rendering until it arrives, so CSS size and delivery directly affect how quickly visitors see a page. Minifying is one part of the picture. This guide measures a real stylesheet before and after minifying and compressing, then covers render blocking, critical CSS, removing unused rules, a spacing rule careless minifiers break, print styles and caching.
A worked example: a real stylesheet
A real 67,154-byte stylesheet, full of explanatory comments, minified to 60,909 bytes, about 9 percent smaller. Compressed with gzip, the original measured 13,954 bytes and the minified version 13,210, a saving of about 5 percent of what is actually transferred. The gain is real but modest, because compression already handles repeated whitespace well. Comments are where minifying saves most, and those are exactly what developers want to keep in the source.
Why CSS size matters
Browsers will not draw a page until the stylesheets in its head have downloaded and been processed, because drawing without them would show unstyled content. On a slow mobile connection, a large stylesheet delays the first paint for every visitor. Keeping CSS small, served from the same domain and cached for repeat visits helps pages appear quickly.
Critical CSS
A common technique places the small amount of CSS needed for the top of the page directly in the head, and loads the full stylesheet without blocking. Visitors see a correctly styled first screen almost immediately while the rest loads. The technique needs care to keep the inline and full styles in step, so it suits pages where speed matters most, such as landing pages.
Unused rules
Themes and frameworks often ship styles for components a site never uses. Removing unused rules usually saves far more than minifying, sometimes over half the file. Tools can detect unused selectors by scanning pages and templates, but check dynamic content carefully, such as classes added by scripts, so needed styles are not stripped.
Spaces inside calc
Inside calc(), the spaces around plus and minus signs are required: calc(100% - 16px) works, while calc(100%-16px) is invalid and the whole declaration is ignored. A correct minifier keeps these spaces, but hand-minified or carelessly processed CSS sometimes loses them, producing layouts that break only in places using calc.
Print and conditional styles
Stylesheets linked with a media attribute that does not match the current situation, such as media="print", do not block rendering. Splitting print styles into their own file with that attribute keeps them out of the critical path, while still applying them when someone prints the page.
Caching and file names
Minified files should be cached for a long time, with a version or content hash in the file name, so returning visitors reuse them. When the stylesheet changes, the new name forces browsers to fetch the update. Without this, visitors may see a mix of old styles and new markup after a change.
Debugging minified CSS
When styles break in production, source maps let browser developer tools show the original files and line numbers. If no source map exists, formatting the minified file makes it readable enough to find the rule involved. Always fix problems in the source file and minify again rather than editing the minified copy.
Combining files
Combining many small stylesheets into one used to be essential when browsers could fetch only a few files at once. With HTTP/2 and HTTP/3, many small files load efficiently, so combining matters less, although very large numbers of tiny files still add overhead. Measure before restructuring an existing setup.
Common mistakes
- Minifying while shipping large amounts of unused CSS.
- Removing the spaces inside calc expressions.
- Linking print styles without a media attribute.
- Editing minified files instead of the source.
Related tools
To make minified CSS readable, use CSS Formatter. To minify markup, try HTML Minifier, and for scripts, JavaScript Minifier.
Shorthand properties
Writing margin: 0 auto instead of four separate margin declarations makes a stylesheet shorter and easier to read. Minifiers that preserve meaning exactly do not combine declarations for you, because doing so safely depends on context, so shorthand is something to use while writing CSS rather than expect from a minifier.
Fonts weigh more than CSS
Custom web fonts are often several times heavier than the stylesheet that loads them. Using font-display: swap shows text immediately in a fallback font, subsetting fonts to the characters you need trims their size, and limiting a site to two or three weights avoids loading files that barely differ visually.
Plugin stylesheets on every page
WordPress plugins often load their stylesheets on every page, even where the plugin is not used, such as a contact form's styles on every blog post. Preventing those files from loading on pages that do not need them, through the plugin's settings or a few lines in the theme, typically saves more than minifying.
Privacy
Minification runs in your browser. Your stylesheet is not uploaded or stored.
Frequently asked questions
Will browsers still read the compressed stylesheet correctly?
Yes. Each edit is one the CSS rules define as having no effect on meaning, such as dropping a comment or a redundant semicolon, so a browser builds exactly the same set of rules from the compact file as from the original.
Why are duplicate rules not combined?
Because where a rule appears in the file decides whether it wins. Two rules with the same selector may both be deliberate, and merging them can change the result, so safe minification sticks to removing bytes rather than restructuring.
How much smaller should I expect the file to be?
A stylesheet that people wrote and commented by hand usually loses about twenty to thirty percent. Framework files that were shipped compact to begin with shrink far less, because there is little whitespace or commentary left to take out of them.
Is minifying still useful when the server uses gzip?
It helps, but less than people expect, because gzip already compresses repeated spaces very well. The larger win usually comes from deleting comments and, separately, from removing CSS the site no longer uses.
Could shortening hex codes alter a colour?
No. Browsers expand a three-digit code by doubling each digit, and the tool only shortens a colour when the full code already has matching pairs, so #ffcc00 and #fc0 are exactly the same colour.
How do I make minified CSS readable again?
Paste it into the CSS Formatter to restore the line breaks and indentation. The comments cannot come back, though, so always keep your original readable file and minify a copy.