Course contentsShow
← Web Development
Lesson 1439 of 2,98226. Code Quality ToolsFree lesson

Common Stylelint Rules

Exploring essential rules for selectors, properties, values, units, and declaration order.

Common Stylelint Rules

You'll learn the most essential Stylelint rules that enforce consistency across selectors, properties, values, units, and declaration order.

Understanding Essential Stylelint Rules

Now that you know how to set up Stylelint and apply standard configurations, it's time to explore the specific rules that do the heavy lifting. Think of these rules as grammar checks for CSS—they catch common mistakes, enforce best practices, and ensure your stylesheets follow a consistent structure.

Key Rule Categories

Selector Rules control how you write class names and selectors. Rules like selector-class-pattern can enforce kebab-case naming (.my-button instead of .myButton), while selector-max-id prevents overuse of ID selectors that create specificity problems.

Property Rules ensure you're using valid CSS properties correctly. property-no-unknown catches typos like colour or margn, while declaration-block-no-duplicate-properties prevents accidentally setting the same property twice.

Value Rules validate what you assign to properties. color-no-invalid-hex catches malformed colors like #fffff, and unit-no-unknown flags incorrect units like 20pixels instead of 20px.

Unit Rules enforce consistency in your measurements. length-zero-no-unit removes unnecessary units from zero values (0 instead of 0px), keeping your CSS cleaner.

Declaration Order rules organize properties logically. order/properties-alphabetical-order or grouped ordering (positioning, box model, typography) makes stylesheets scannable and predictable—like organizing a toolbox where you always know where to find what you need.

These rules work together to catch errors before they reach production and maintain a consistent coding style across your entire team.

Key Takeaway: Common Stylelint rules target selectors, properties, values, units, and declaration order to enforce consistency, catch errors, and maintain best practices throughout your stylesheets.