
Security News
GitHub Actions Pricing Whiplash: Self-Hosted Actions Billing Change Postponed
GitHub postponed a new billing model for self-hosted Actions after developer pushback, but moved forward with hosted runner price cuts on January 1.
css-declaration-sorter
Advanced tools
A Node.js module and PostCSS plugin to sort CSS, SCSS or Less declarations based on their property names. Ensuring styling is organized, more consistent and in order... The goal of this package is to sort the source code of a project in the build process or to decrease the distributed CSS gzipped size.
Check out the Prettier plugin for usage with a variety of file formats.
Input:
body {
display: block;
animation: none;
color: #C55;
border: 0;
}
Output:
body {
animation: none;
border: 0;
color: #C55;
display: block;
}
Alphabetical
alphabetical
Default, order in a simple alphabetical manner from a - z.
SMACSS
smacss
Order from most important, flow affecting properties, to least important properties.
Concentric CSS
concentric-css
Order properties applying outside the box model, moving inward to intrinsic changes.
Frakto
frakto
Order from the outermost layout and positioning rules, moving inward through structure, style, and interaction — inspired by the browser’s render tree.
Following the PostCSS plugin guidelines, this package depends on PostCSS as a peer dependency:
npm install postcss 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, the postcss-cli package is a required dependency.
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
Sorting all files in a directory with SCSS syntax using postcss-scss by overwriting:
postcss ./src/**/*.scss --syntax postcss-scss --use css-declaration-sorter --replace --no-map
Sorting all files in the directory with SCSS syntax and SMACSS order by overwriting, using package.json configuration:
"postcss": {
"syntax": "postcss-scss",
"map": false,
"plugins": {
"css-declaration-sorter": { "order": "smacss" }
}
}
postcss ./src/**/*.scss --replace --config package.json
import postcss from 'postcss';
import { cssDeclarationSorter } from 'css-declaration-sorter';
postcss([cssDeclarationSorter({ order: 'smacss' })])
.process('a { color: hyperblue; display: block; }', { from: undefined })
.then(result => console.log(
result.css === 'a { display: block; color: hyperblue; }'
));
View more usage examples in combination with other tools.
Type: string or function
Default: alphabetical
Options: alphabetical, smacss, concentric-css
Provide the name of one of the built-in sort orders or a comparison function that is passed to (Array.sort). This function receives two declaration names and is expected to return -1, 0 or 1 depending on the wanted order.
Type: Boolean
Default: false
To prevent breaking legacy CSS where shorthand declarations override longhand declarations (also taking into account vendor prefixes) this option can enabled. For example animation-name: some; animation: greeting; will be kept in this order when keepOverrides is true.
postcss-sorting is similar to css-declaration-sorter in that it sorts CSS properties according to a specified order. However, it also allows for sorting at-rules and rules within CSS files, providing a more comprehensive sorting capability.
stylelint-order is a plugin for stylelint that checks the order of content within declaration blocks. While it does not automatically sort the CSS, it can enforce a specific order and is often used in conjunction with stylelint to maintain code quality.
perfectionist is a PostCSS plugin that not only sorts declarations but also beautifies CSS with consistent spacing and syntax. It offers a more stylistic approach to organizing CSS compared to css-declaration-sorter, which focuses solely on sorting declarations.
FAQs
Sorts CSS declarations fast and automatically in a certain order.
The npm package css-declaration-sorter receives a total of 4,968,655 weekly downloads. As such, css-declaration-sorter popularity was classified as popular.
We found that css-declaration-sorter demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
GitHub postponed a new billing model for self-hosted Actions after developer pushback, but moved forward with hosted runner price cuts on January 1.

Research
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.

Security News
Socket CTO Ahmad Nassri shares practical AI coding techniques, tools, and team workflows, plus what still feels noisy and why shipping remains human-led.