Linters
What is Stylelint? An introduction to the CSS linter
Stylelint is a CSS linter that helps avoid errors and enforce conventions. It ships with over 150 built-in rules for modern CSS and can fix many problems automatically. It also understands CSS-like languages and styles embedded in other file types.
- Tool
- Stylelint
- Made by
- Stylelint
- Official site
- stylelint.io
- Category
- Linters
Who makes Stylelint
Stylelint is maintained by volunteers, and its official website is linked below. Its governance model requires consensus for changes to the project, so decisions are shared rather than made by one person.
Official website: stylelint.io
What Stylelint is for
Stylelint is for catching mistakes in stylesheets and keeping them consistent. It detects invalid constructs, such as malformed grid areas, and unknown things, such as misspelled property names. These are errors that a browser may silently ignore.
It also enforces conventions. It can require naming patterns, for example for custom properties, and it can set limits, such as on the number of ID selectors.
Who Stylelint is for
Stylelint is aimed at CSS developers and at teams enforcing CSS conventions. Its shareable configs suit teams that want every project to follow the same rules.
Notable capabilities
Stylelint pairs a broad built-in rule set with options for extending and sharing configuration.
Its main capabilities are:
- Built-in rules: over 150 rules cover modern CSS.
- Plugins: plugins let you add custom rules for conventions the built-in set does not cover.
- Autofix: Stylelint can automatically fix problems where possible.
- Shareable configs: configurations can be created or extended, which makes it practical to reuse one setup across projects.
- Embedded styles: it can extract styles embedded in HTML, Markdown and CSS-in-JS.
- CSS-like languages: it can parse SCSS, Sass, Less and SugarSS.
- Testing: it has a large unit test suite.
- Stable versioning: it uses a specific flavour of semantic versioning because it is a code quality tool.
How Stylelint fits linters
In the linters category, Stylelint covers stylesheets, where many general-purpose linters do not look. Its focus is on errors and conventions, not on layout of the code. The project recommends using a pretty printer like Prettier alongside Stylelint, so formatting and linting are handled by separate tools.
Because minor updates may report more errors, the project recommends using the tilde in package.json to keep results stable. This follows from the versioning approach described above: a new rule or a stricter check can change what a lint run reports.
In Linthelm's wider niche of linters, static analysis and code quality, Stylelint is the CSS-focused option. It brings the same automated checking that developers expect for scripting languages to styling code.
Frequently asked questions
What is Stylelint used for?
Stylelint is used to lint CSS. It helps avoid errors and enforce conventions, and it can automatically fix problems where possible.
Does Stylelint support SCSS and Less?
Yes. It can parse CSS-like languages including SCSS, Sass, Less and SugarSS.
Can Stylelint check CSS inside other files?
Yes. It can extract embedded styles from HTML, Markdown and CSS-in-JS.
Should I use Stylelint with Prettier?
The project recommends using a pretty printer like Prettier alongside Stylelint.
Who maintains Stylelint?
Stylelint is maintained by volunteers. Changes require consensus under its governance model.
Linthelm is independent and is not affiliated with Stylelint. Product names belong to their owners. Features change; confirm details on the official website.