Skip to content

Getting started

You can quickly get started by extending an appropriate shared config.

Use npm and our create tool to automatically setup Stylelint and extend our standard config:

Terminal window
npm create stylelint@latest

Alternatively, you can manually setup Stylelint to lint CSS.

  1. Create a stylelint.config.mjs configuration file in the root of your project with the following content:
    /** @type {import('stylelint').Config} */
    export default {
    extends: ["stylelint-config-standard"]
    };
  2. Use npm (or your preferred package manager) to add the related dependencies:
    Terminal window
    npm add -D stylelint stylelint-config-standard
  3. Run Stylelint on all the CSS files in your project:
    Terminal window
    npx stylelint "**/*.css"

Once you’re up and running, you can customize Stylelint.

Linting CSS-like languages and CSS within containers

Section titled “Linting CSS-like languages and CSS within containers”

You can extend a community config to lint:

  • CSS-like languages, e.g. SCSS, Sass and Less
  • CSS within containers, e.g. in HTML, CSS-in-JS and Vue SFCs

For example, to lint SCSS you can extend the SCSS community config:

  1. Create a stylelint.config.mjs configuration file in the root of your project with the following content:
    /** @type {import('stylelint').Config} */
    export default {
    extends: ["stylelint-config-standard-scss"]
    };
  2. Use npm (or your preferred package manager) to add the related dependencies:
    Terminal window
    npm add -D stylelint stylelint-config-standard-scss
  3. Run Stylelint on all the SCSS files in your project:
    Terminal window
    stylelint "**/*.scss"

The config includes the:

You’ll find more community configs in Awesome Stylelint.

If a shared config isn’t available for your preferred language or container, you can install the appropriate custom syntax and use the customSyntax option yourself.

For example, to lint CSS inside of Lit elements using the Lit custom syntax:

  1. Create a stylelint.config.mjs configuration file in the root of your project with the following content:
    /** @type {import('stylelint').Config} */
    export default {
    extends: "stylelint-config-standard",
    customSyntax: "postcss-lit"
    };
  2. Use npm (or your preferred package manager) to add the related dependencies:
    Terminal window
    npm add -D stylelint stylelint-config-standard postcss-lit
  3. Run Stylelint on all the JavaScript files in your project:
    Terminal window
    stylelint "**/*.js"

You’ll find more custom syntaxes in Awesome Stylelint.

If you want to lint more than one language or container, you can use the overrides property.

For example, to lint CSS files and the CSS within Lit Elements you can update your configuration to:

/** @type {import('stylelint').Config} */
export default {
extends: ["stylelint-config-standard"],
overrides: [
{
files: ["*.js"],
customSyntax: "postcss-lit"
}
]
};

And then run Stylelint on both your CSS and JavaScript files:

Terminal window
stylelint "**/*.{css,js}"