githubEdit

css-declaration-sorter

CSS declaration sorter logo

CSS Declaration Sorter

Travis Build Statusarrow-up-right npm versionarrow-up-right David Dependencies Statusarrow-up-right David devDependencies Statusarrow-up-right

A Node.js module and PostCSSarrow-up-right 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 packagearrow-up-right for individual usage.

Alphabetical example

Input:

body {
    display: block;
    animation: none;
    color: #C55;
    border: 0;
}

Output:

body {
    animation: none;
    border: 0;
    color: #C55;
    display: block;
}

Niceness

Sorting orders

  • Alphabetically alphabetically Default, ordering in a simple alphabetical manner from a - z.

  • SMACSSarrow-up-right smacss Ordering from most important, flow affecting properties, to least important properties.

    • Box

    • Border

    • Background

    • Text

    • Other

  • Concentric CSSarrow-up-right concentric-css Starts outside the box model, moves inward.

    • Positioning

    • Visibility

    • Box model

    • Dimensions

    • Text

  • Custom order Provide your own order by passing the location of a JSON file containing an array.

Usage

npm install css-declaration-sorter --save-dev

CLI

This module does not include its own CLI but works with the official PostCSS CLIarrow-up-right. To use the examples below, install postcss-cli or prefix with npx.

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

Vanilla JS

Gulp

See PostCSSarrow-up-right documentation for more examples and other environments.

Last updated

Was this helpful?