What is CSS Specificity?

Specificity is the four-column scoring system browsers use to decide which CSS rule wins. Inline > ID > class > element — here's how it works and why it matters.

4 min read
CSS
Browser
Fundamentals

TABLE OF CONTENTS
What is CSS Specificity?

CSS Specificity is the system browsers use to decide which style rule wins when multiple rules target the same element. It's a weight-based scoring system — each selector type contributes points, and the rule with the highest total wins.


How Specificity Is Calculated

Specificity is a four-column score: inline, IDs, classes/attributes/pseudo-classes, elements/pseudo-elements.

SelectorInlineIDsClasses/attrsElements
div0001
.card0010
#header0100
div.card0011
#nav .link0110
style="..."1000

Each column is independent — higher columns always beat lower ones. A selector with 1 ID always beats a selector with 1000 classes. Think of it as comma-separated numbers: 0,1,0,0 beats 0,0,99,0.


The Cascade: What Happens When Specificity Is Equal

When two rules have the same specificity, the cascade kicks in: the rule that appears later in the stylesheet wins.

Source order also applies across origins. The cascade order, from lowest to highest priority:

  1. User-agent styles (browser defaults)
  2. User styles (browser extensions, user preferences)
  3. Author styles (your CSS)
  4. Author !important
  5. User !important
  6. User-agent !important

Inheritance

Some CSS properties inherit — they flow from parent to child automatically:

Properties like color, font-size, font-family, line-height, text-align, and visibility inherit. Properties like width, height, margin, padding, border, display, and background do not.

Inherited values have zero specificity — any direct rule on the element, even with a universal selector (*), overrides the inherited value.


!important

!important bypasses specificity entirely for the property it's applied to. It creates a separate cascade tier:

!important on a shorthand property (background) breaks into individual properties. It doesn't make the entire rule !important — just the declarations marked with it.

Overusing !important makes the cascade unmanageable. It's a last resort for overriding styles you don't control (third-party embeds, injected stylesheets), not a tool for your own CSS.


Why Specificity Matters for Performance

The browser resolves specificity and cascade during CSSOM construction — step 2 of the rendering pipeline. Deeply nested selectors don't just make CSS harder to maintain; they cost more to match:

Modern browsers are extremely fast at selector matching, so specificity alone is rarely a bottleneck. But the pattern it encourages — shallow, class-based selectors — produces smaller stylesheets that parse faster and are easier to reason about.


Specificity is one of those concepts that feels like trivia until a style isn't applying and you can't figure out why. Understanding the four-column system — inline > ID > class > element — makes those debugging sessions ten seconds instead of ten minutes.


Let's Connect

© 2026 Naveen Karthik // Built with React & MUI