Module 4 · Lesson 2 of 414/60 in the course~18 min
Module lessons (2/4)
Specificity & The Cascade: Who Wins & Why
Lesson preview5 hands-on exercises readyModern HTML & CSS · CSS Selectors, Cascade & Specificity
Compute (ID, Class, Element) specificity tuples, understand source order, and avoid !important warfare.
What you'll learn in this lesson
- Calculate CSS Specificity
(A, B, C)tuples cleanly (IDs,Classes/Attributes/Pseudo-classes,Elements/Pseudo-elements). - Predict which CSS rule wins when two selectors match the same element using Origin -> Importance -> Layer -> Specificity -> Source Order.
- Explain why keeping specificity flat prevents
!importantescalation wars.
Overview
Almost every developer hits this early frustration: you add .btn-primary { background: teal; } at the bottom of your CSS, hit refresh, and nothing changes because #header .actions button earlier in the file beat it silently.
CSS resolves competing declarations on the same element in a strict Cascade hierarchy:
Sections covered in this lesson
- 1Why Did My Style Get Ignored?
- 2Play the Specificity & Cascade Battle Arena
Pro Lesson · CSS Selectors, Cascade & Specificity
Unlock "Specificity & The Cascade: Who Wins & Why" and the full Modern HTML & CSS curriculum
Compute (ID, Class, Element) specificity tuples, understand source order, and avoid !important warfare.
Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.
- Instant access to all advanced modules in Modern HTML & CSS plus 17 more courses
- Hands-on browser exercises with automated test suites and solutions
- 14-day money-back guarantee processed via Paddle.com
14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.