Command Palette

Search for a command to run...

Hectal
Phase 2Beginner3 of 12 in CSS

The Cascade, Specificity and Inheritance

Why one CSS rule beats another: origins, !important, cascade layers, specificity scores, source order and inheritance, step by step.

Sooner or later every CSS learner writes a rule, saves, and nothing changes. The rule isn't broken: another rule is winning. This phase teaches the exact algorithm the browser uses to pick the winner when several rules set the same property on the same element. That algorithm is called the cascade, and it is the C in CSS.

You'll learn the cascade's steps in order (origin and importance, cascade layers, specificity, order of appearance), how to score any selector's specificity by hand, how values flow from parents to children through inheritance, what !important really does and why it causes trouble, and how modern cascade layers (@layer) let you control the whole thing on purpose.

After this phase, "my CSS doesn't work" becomes a question you can answer in a minute with DevTools. It builds on Phase 1 (Selectors) and everything later (layout, components, architecture in Phase 11) depends on it.

0/5 · 0%
5 topics ~2 h 15 code blocks & diagrams
Start with the first topic

Practise this phase

Hands-on exercises: write the code, see your page live, and press Check to have it tested automatically.