DevPrep
  • Interview Prep
  • Projects
  • Resources
  • Pricing
  • About Us
Submit Question
DevPrep
  • Pricing
  • About Us
Submit Question
← From Beginner to Expert in Fundamentals of Frontend
  • The Box Model
  • Specificity & The Cascade
  • CSS Units Deep Dive
  • Stacking Contexts & Z-Index
  • Flexbox Mastery
  • CSS Grid Mastery
  • Centering, Subgrid & Container Queries
  • CSS Custom Properties & Variables
  • Selectors: :has(), Pseudo-classes & Pseudo-elements
  • Responsive Functions: calc(), clamp(), min(), max()
  • Media Queries & Mobile-First Design
  • Transitions & Animations
  • Transforms, Filters & Clipping
  • CSS Methodologies: BEM, CSS-in-JS & Tailwind
  • Typography, Color Spaces & Dark Mode
  • CSS Performance & Optimization
  • CSS Interview Questions — Part 1
  • CSS Interview Questions — Part 2
← From Beginner to Expert in Fundamentals of Frontend

Specificity & The Cascade

18 min read
SpecificityCascadeInheritance!important:where():is()Selector Weight

How the Browser Decides Which Rule Wins

When multiple CSS rules target the same element, the browser needs a tiebreaker system. This system is called The Cascade, and it follows a strict priority order.

The Cascade Priority (Highest to Lowest)

PrioritySourceExample
1 (Highest)!important declarationscolor: red !important;
2Inline styles<p style="color: blue">
3ID selectors#header { color: green; }
4Class / Attribute / Pseudo-class.nav { color: orange; }
5Element / Pseudo-elementp { color: black; }
6 (Lowest)Universal selector* { color: gray; }

Calculating Specificity

Specificity is calculated as a tuple: (Inline, IDs, Classes, Elements)

SelectorSpecificityScore
p(0, 0, 0, 1)1
.card(0, 0, 1, 0)10
#main(0, 1, 0, 0)100
#main .card p(0, 1, 1, 1)111
style="..."(1, 0, 0, 0)1000
.card.active:hover(0, 0, 3, 0)30

Inheritance

Some CSS properties are inherited by child elements, others are not:

Inherited ✅NOT Inherited ❌
colorborder
font-familypadding
font-sizemargin
line-heightwidth / height
visibilitybackground
cursordisplay

Use inherit, initial, or unset to control inheritance explicitly.

The :where() and :is() Difference

:is() takes the specificity of its most specific argument. :where() always has zero specificity, making it perfect for resets and defaults that should be easily overridable.

Practice

  • JavaScript
  • DSA
  • Machine Coding
  • System Design

Resources

  • Learning Tracks
  • Articles
  • Roadmaps
  • Compare Concepts
  • Glossary
  • Developer Tools
  • All Questions

Company

  • About
  • Pricing

Legal

  • Privacy Policy
  • Terms of Service
DevPrep

© 2026 DevPrep. All rights reserved.