explaingit

css/csso

3,795JavaScriptAudience · developerComplexity · 2/5Setup · easy

TLDR

CSSO is a JavaScript CSS minifier that shrinks CSS files by removing dead code, shortening values, and merging duplicate rules, producing smaller files than basic minifiers.

Mindmap

mindmap
  root((CSSO))
    What it does
      Remove dead code
      Compress value syntax
      Merge duplicate rules
    Integrations
      Gulp and Grunt
      webpack loader
      PostCSS plugin
      VS Code Atom Sublime
    Usage
      Node.js API
      Browser bundle
      csso-cli command line
    Options
      Source maps
      Disable restructuring
      HTML usage data input
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Reduce CSS file size in a web project before publishing so pages load faster for visitors.

USE CASE 2

Integrate CSS minification into a Gulp, Grunt, or webpack build pipeline automatically.

USE CASE 3

Remove unused CSS by passing HTML usage data so CSSO knows which selectors are actually referenced.

USE CASE 4

Generate source maps so browser DevTools still show readable original CSS while the minified version runs.

Tech stack

JavaScriptNode.jsPostCSS

Getting it running

Difficulty · easy Time to first run · 5min
No explicit license stated in the explanation, check the repository for terms.

In plain English

CSSO (CSS Optimizer) is a JavaScript tool that makes CSS files smaller. CSS is the language that controls the visual appearance of web pages, and CSS files can grow large as projects expand. Smaller files load faster for visitors, which is why developers typically run CSS through a minifier before publishing a website. What sets CSSO apart from simpler minifiers is that it does three levels of work. The first is cleaning: removing comments, extra whitespace, and rules that have no effect. The second is compression: replacing longer values with shorter equivalents, for example turning the color value #ff0000 into the word red, which takes fewer characters. The third is restructuring: merging separate CSS rules that target the same elements, combining duplicate property declarations, and reordering things where safe to do so. These structural changes can produce meaningfully smaller files than compression alone. The library works in Node.js and can also be loaded directly in a browser. You pass it a string of CSS and it returns a minified string. The API has options to disable the restructuring step if you want safer but less aggressive minification, to generate source maps (files that let browser developer tools show you the original unminified code even when the minified version is running), and to pass usage data that tells CSSO which selectors and properties are actually used in your HTML so it can remove the rest. Plugins and integrations exist for the common JavaScript build tools: Gulp, Grunt, webpack (as both a loader and a plugin), PostCSS, and editors like VS Code, Atom, and Sublime Text. There is also a command-line version called csso-cli for running it from a terminal without writing code. The README is detailed and includes code examples for every part of the API.

Copy-paste prompts

Prompt 1
How do I add CSSO to my webpack config to automatically minify all CSS files during the build?
Prompt 2
Show me how to use the CSSO Node.js API to minify a CSS string and return a source map.
Prompt 3
How do I pass HTML usage data to CSSO so it strips out CSS selectors my pages never use?
Prompt 4
How do I use csso-cli from the terminal to minify a single CSS file and save the result?
Open on GitHub → Explain another repo

← css on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.