{"id":25147,"library":"csso","title":"CSSO – CSS Optimizer","description":"CSSO (CSS Optimizer) is a CSS minifier that performs cleaning (removing redundancies), compression (replacing with shorter forms), and restructuring (merging declarations/rules) to reduce CSS file size. Version 5.0.5 (latest stable) supports ESM and CommonJS dual module, CSS Selectors Level 4, and ships TypeScript definitions. It is built on CSSTree for AST parsing and manipulation. Compared to other minifiers like clean-css, CSSO offers structural optimizations beyond simple compression. Maintained actively with frequent releases.","status":"active","version":"5.0.5","language":"javascript","source_language":"en","source_url":"https://github.com/css/csso","tags":["javascript","css","compress","minifier","minify","optimise","optimisation","csstree"],"install":[{"cmd":"npm install csso","lang":"bash","label":"npm"},{"cmd":"yarn add csso","lang":"bash","label":"yarn"},{"cmd":"pnpm add csso","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"CSSO uses CSSTree for CSS parsing, AST traversal, and CSS generation. Required at runtime.","package":"css-tree","optional":false}],"imports":[{"note":"ESM is recommended; CommonJS also supported via require().","wrong":"const { minify } = require('csso');","symbol":"minify","correct":"import { minify } from 'csso';"},{"note":"The 'syntax' object provides CSSTree API. Access via 'csso/syntax' entry point available since v5.0.1.","wrong":"const syntax = require('csso/syntax');","symbol":"syntax","correct":"import { syntax } from 'csso';"},{"note":"compress() is not exported from the main csso entry. Use 'csso/syntax' for step-by-step AST manipulation.","wrong":"import { compress } from 'csso';","symbol":"compress","correct":"import { compress } from 'csso/syntax';"},{"note":"parse() is part of the CSSTree API available via 'csso/syntax'.","wrong":"import syntax from 'csso';","symbol":"parse","correct":"import { parse } from 'csso/syntax';"},{"note":"ESM import preferred; generate() converts AST back to CSS string.","wrong":"const { generate } = require('csso/syntax');","symbol":"generate","correct":"import { generate } from 'csso/syntax';"}],"quickstart":{"code":"import { minify } from 'csso';\n\nconst inputCSS = `\n  .test {\n    color: #ff0000;\n    font-weight: bold;\n  }\n  .test {\n    color: green;\n  }\n`;\n\nconst result = minify(inputCSS);\nconsole.log(result.css);\n// Output: .test{color:green;font-weight:bold}\n\n// Step-by-step with syntax\nimport { parse, compress, generate } from 'csso/syntax';\n\nconst ast = parse(inputCSS);\nconst compressed = compress(ast);\nconst outputCSS = generate(compressed.ast);\nconsole.log(outputCSS);\n// Same output","lang":"typescript","description":"Demonstrates two ways to use CSSO: simple minify() call and step-by-step AST compression via syntax module."},"warnings":[{"fix":"Use import syntax or ensure your project supports CommonJS with require('csso').","message":"CSSO v5 is ESM by default; CommonJS is supported but requires Node.js >=12.20.0 and using require().","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Upgrade Node.js to ^12.20.0, ^14.13.0, or >=15.0.0.","message":"Node.js versions <12.20.0, <14.13.0, <15.0.0 are not supported in v5.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"npm install csso@latest","message":"CSSO v4 is no longer maintained; upgrade to v5 for latest features and security fixes.","severity":"deprecated","affected_versions":">=4.0.0 <5.0.0"},{"fix":"If relying on syntax API, consider using CSSTree directly.","message":"CSSO does not guarantee API stability behind the 'syntax' field; it may change with CSSTree updates.","severity":"gotcha","affected_versions":"*"},{"fix":"Use const compressedAst = compress(ast).ast;","message":"When using 'csso/syntax', the compress() function returns an object with .ast property, not the AST directly.","severity":"gotcha","affected_versions":">=5.0.0"},{"fix":"Import from 'csso/syntax' for step-by-step AST manipulation.","message":"The default export only provides minify(); other functions like compress/parse/generate are under 'csso/syntax'.","severity":"gotcha","affected_versions":">=5.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use import or require('csso') which automatically resolves to CommonJS.","cause":"Trying to require() the ESM bundle instead of CommonJS entry.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/csso/dist/csso.js from /path/to/app.js not supported."},{"fix":"Use import { minify } from 'csso';","cause":"Using default import instead of named import: import csso from 'csso' yields the module object, not minify directly.","error":"TypeError: csso.minify is not a function"},{"fix":"Update to csso@5.0.1 or later. npm install csso@latest","cause":"csso/syntax was added in v5.0.1; trying to use it with an older version.","error":"Cannot find module 'csso/syntax'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}