CSS Declaration Sorter
A Node.js module and PostCSS plugin to sort CSS declarations based on their property names. Ensuring the CSS is organized, more consistent and in order... Besides, sorted CSS is smaller when gzipped because there will be more similar strings. The intention of this module is to sort the source CSS code of a project in the build process. Check out the Atom package for individual usage.
- Up-to-date CSS properties fetched from the MDN Web Platform.
- Sort using your own defined order.
- Nested rules sorting support.
- Less and SCSS support when combined with either postcss-scss or postcss-less.
- Thought-out sorting orders out of the box, approved by their authors.
Default, ordering in a simple alphabetical manner from a - z.
Ordering from most important, flow affecting properties, to least important properties.
Starts outside the box model, moves inward.
- Box model
Provide your own order by passing the location of a JSON file containing an array.
npm install css-declaration-sorter --save-dev
This module does not include its own CLI but works with the official PostCSS CLI. To use the examples below, install
postcss-cli or prefix with
Piping out result from file:
postcss input.css --use css-declaration-sorter | cat
Sorting multiple files by overwriting:
postcss *.css --use css-declaration-sorter --replace --no-map
const fs = ;const postcss = ;const cssDeclarationSorter = ;;
const gulp = ;const gulpPostcss = ;const cssDeclarationSorter = ;gulp;
See PostCSS documentation for more examples and other environments.