CLEANCSS(1)

πŸ’– NAME πŸ’–

okay so bestie, meet cleancss β€” a fast and efficient CSS optimizer. she takes your chunky stylesheet and makes it ✨snatched✨. no cap.


πŸ¦‹ SYNOPSIS πŸ¦‹

cleancss [options] <source-file ...>

πŸ‘‘ OPTIONS πŸ‘‘

  • -v, --version β€” outputs the version number. that's the whole job, and she does it flawlessly πŸ’…
  • -c, --compatibility [ie7|ie8] β€” forces compatibility mode. (there are advanced examples in the Readme if you wanna go deeper, iykyk)
  • -d, --debug β€” shows debug information: the minification time and the compression efficiency. receipts, basically 🧾
  • -f, --format <options> β€” controls the output formatting. examples are down below ⬇️
  • -o, --output [output-file] β€” uses [output-file] as the output instead of STDOUT. she can pick a destination, she's not like other girls.
  • -O <n> [optimizations] β€” turns on level n optimizations. optionally she'll accept a list of fine-grained options too. defaults to 1. examples below πŸ”₯
  • --inline [rules] β€” enables inlining for the listed sources. defaults to local.
  • --inline-timeout [seconds] β€” per-connection timeout when she's out here fetching remote stylesheets. defaults to 5 seconds.
  • --remove-inlined-files β€” removes files that were inlined in <source-file ...> or via @import statements.
  • --skip-rebase β€” disables URLs rebasing.
  • --source-map β€” enables building the input's source map.
  • --source-map-inline-sources β€” enables inlining sources inside source maps.
  • --input-source-map [file] β€” specifies the path of the input source map file.
  • -h, --help β€” outputs usage information. the iconique classic.

πŸŽ€ Examples: πŸŽ€

%> cleancss one.css
%> cleancss -o one-min.css one.css
%> cleancss -o merged-and-minified.css one.css two.css three.css
%> cleancss one.css two.css three.css | gzip -9 -c > merged-minified-and-gzipped.css.gz

🌈 Formatting options: 🌈

%> cleancss --format beautify one.css
%> cleancss --format keep-breaks one.css
%> cleancss --format 'indentBy:1;indentWith:tab' one.css
%> cleancss --format 'breaks:afterBlockBegins=on;spaces:aroundSelectorRelation=on' one.css

so here's the whole menu of formatting knobs, bestie:

  • breaks β€” controls where to insert breaks.
    • afterAtRule β€” controls if a line break comes after an at-rule, e.g. @charset. defaults to off (alias to false).
    • afterBlockBegins β€” controls if a line break comes after a block begins, e.g. @media. defaults to off.
    • afterBlockEnds β€” controls if a line break comes after a block ends. defaults to off.
    • afterComment β€” controls if a line break comes after a comment. defaults to off.
    • afterProperty β€” controls if a line break comes after a property. defaults to off.
    • afterRuleBegins β€” controls if a line break comes after a rule begins. defaults to off.
    • afterRuleEnds β€” controls if a line break comes after a rule ends. defaults to off.
    • beforeBlockEnds β€” controls if a line break comes before a block ends. defaults to off.
    • betweenSelectors β€” controls if a line break comes between selectors. defaults to off.
  • indentBy β€” controls the number of characters to indent with. defaults to 0.
  • indentWith β€” controls the character to indent with. can be space or tab. defaults to space.
  • spaces β€” controls where to insert spaces.
    • aroundSelectorRelation β€” controls if spaces come around selector relations, e.g. div > a. defaults to off.
    • beforeBlockBegins β€” controls if a space comes before a block begins, e.g. .block {. defaults to off.
    • beforeValue β€” controls if a space comes before a value, e.g. width: 1rem. defaults to off.
  • wrapAt β€” controls the maximum line length. defaults to off.

⭐ Level 0 optimizations: ⭐

%> cleancss -O0 one.css

πŸ’… Level 1 optimizations: πŸ’…

%> cleancss -O1 one.css
%> cleancss -O1 removeQuotes:off;roundingPrecision:4;specialComments:1 one.css
%> cleancss -O1 all:off;specialComments:1 one.css

and the fine-grained level 1 girlies:

  • cleanupCharsets β€” controls @charset moving to the front of a stylesheet. defaults to on.
  • normalizeUrls β€” controls URL normalization. defaults to on.
  • optimizeBackground β€” controls background property optimizations. defaults to on.
  • optimizeBorderRadius β€” controls border-radius property optimizations. defaults to on.
  • optimizeFilter β€” controls filter property optimizations. defaults to on.
  • optimizeFontWeight β€” controls font-weight property optimizations. defaults to on.
  • optimizeOutline β€” controls outline property optimizations. defaults to on.
  • removeEmpty β€” controls removing empty rules and nested blocks. defaults to on (since 4.1.0).
  • removeNegativePaddings β€” controls removing negative paddings. defaults to on.
  • removeQuotes β€” controls removing quotes when they're unnecessary. defaults to on.
  • removeWhitespace β€” controls removing unused whitespace. defaults to on.
  • replaceMultipleZeros β€” controls removing redundant zeros. defaults to on.
  • replaceTimeUnits β€” controls replacing time units with shorter values. defaults to on.
  • replaceZeroUnits β€” controls replacing zero values with units. defaults to on.
  • roundingPrecision β€” rounds pixel values to N decimal places; off disables rounding. defaults to off.
  • selectorsSortingMethod β€” denotes the selector sorting method; can be natural or standard. defaults to standard.
  • specialComments β€” denotes a number of /*! ... */ comments preserved. defaults to all.
  • tidyAtRules β€” controls at-rules (e.g. @charset, @import) optimizing. defaults to on.
  • tidyBlockScopes β€” controls block scopes (e.g. @media) optimizing. defaults to on.
  • tidySelectors β€” controls selectors optimizing. defaults to on.

πŸ”₯ Level 2 optimizations: πŸ”₯

%> cleancss -O2 one.css
%> cleancss -O2 mergeMedia:off;restructureRules:off;mergeSemantically:on;mergeIntoShorthands:off one.css
%> cleancss -O2 all:off;removeDuplicateRules:on one.css

and the level 2 menu, all of it, no skips:

  • mergeAdjacentRules β€” controls adjacent rules merging. defaults to on.
  • mergeIntoShorthands β€” controls merging properties into shorthands. defaults to on.
  • mergeMedia β€” controls @media merging. defaults to on.
  • mergeNonAdjacentRules β€” controls non-adjacent rule merging. defaults to on.
  • mergeSemantically β€” controls semantic merging. defaults to off.
  • overrideProperties β€” controls property overriding based on understandability. defaults to on.
  • reduceNonAdjacentRules β€” controls non-adjacent rule reducing. defaults to on.
  • removeDuplicateFontRules β€” controls duplicate @font-face removing. defaults to on.
  • removeDuplicateMediaBlocks β€” controls duplicate @media removing. defaults to on.
  • removeDuplicateRules β€” controls duplicate rules removing. defaults to on.
  • removeEmpty β€” controls removing empty rules and nested blocks. defaults to on (since 4.1.0).
  • removeUnusedAtRules β€” controls unused at rule removing. defaults to off (since 4.1.0).
  • restructureRules β€” controls rule restructuring. defaults to off.
  • skipProperties β€” controls which properties won't be optimized. defaults to an empty list, which means all of them will be optimized (since 4.1.0).

πŸ’œ this page is from cleancss 4.3.0, dated February 2020, and it lives in section 1 of the manual (User Commands). go forth and minify, bestie 🫢✨