<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/css-specificity-the-cascade-and-inheritance-explained-3ldecubog" -->

---
title: CSS Specificity, the Cascade, and Inheritance Explained
description: When several CSS rules set the same property on one element, the browser settles it one property at a time by asking three questions in order: which is more...
canonical: https://daily.dev/posts/css-specificity-the-cascade-and-inheritance-explained-3ldecubog
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: CSS Specificity, the Cascade, and Inheritance Explained | daily.dev
og:description: When several CSS rules set the same property on one element, the browser settles it one property at a time by asking three questions in order: which is more...
og:url: https://daily.dev/posts/css-specificity-the-cascade-and-inheritance-explained-3ldecubog
og:image: https://api.daily.dev/og/posts/3LdECuboG.png
og:image:alt: CSS Specificity, the Cascade, and Inheritance Explained
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# CSS Specificity, the Cascade, and Inheritance Explained

**[Kirupa](https://daily.dev/sources/kirupa)** · 12 min read · 0 upvotes · 0 comments

## Summary

When several CSS rules set the same property on one element, the browser settles it one property at a time by asking three questions in order: which is more important, which is more specific, and which comes last. Specificity counts IDs, then classes, then types, compared column by column. So #intro (1-0-0) beats .card .note:hover (0-3-0), and no number of classes outranks an ID. Inline styles beat every selector, and !important beats inline styles. Inherited values have no specificity, so even a plain p rule beats an inherited color.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.kirupa.com/html5/css_specificity_cascade_inheritance.htm>

## Questions this post answers

### Why does a single ID selector beat any number of class selectors in CSS?

Specificity is compared one column at a time: IDs first, then classes, then types. The columns never carry over into each other, so #intro at 1-0-0 beats .card .note:hover at 0-3-0. Even a selector with 11 classes can't outrank a single ID. It works like comparing version numbers rather than adding up totals.

_Developers untangling CSS conflicts keep their front-end fundamentals sharp on daily.dev._

### Why does a plain p rule override the color my paragraph inherits from a parent with a more specific selector?

An inherited value is the weakest thing in the cascade and has no specificity at all. A rule like #main { color: red } only matches the #main element itself, so paragraphs inside only inherit red. A p { color: gray } rule targets them directly, so it wins even though its selector is far less specific.

_If styles keep surprising you, daily.dev surfaces CSS debugging insights worth knowing._

### How do I debug a CSS rule that isn't applying in the browser?

Check that the selector matches, the declaration is valid, no rule wins on specificity or order, the rule isn't only styling a parent (so the element merely inherits), and no !important or inline style interferes. In the developer tools Styles panel, losing declarations are crossed out, and Chrome and Firefox show a selector's specificity on hover.

_Anyone chasing stubborn styling bugs will find daily.dev useful for web debugging practices._

## Similar posts on daily.dev

- [Alternatives to the \!important Keyword](https://daily.dev/posts/alternatives-to-the-important-keyword-5xs5ckzta) · CSS-Tricks · 6 upvotes · 0 comments
- [Warning: containment breach in cascade layer\!](https://daily.dev/posts/warning-containment-breach-in-cascade-layer--rxkfwmmwx) · dbushell · 8 upvotes · 0 comments
- [Wanna see a CSS magic trick?](https://daily.dev/posts/wanna-see-a-css-magic-trick--wta2tfzuo) · Stack Overflow Blog · 76 upvotes · 4 comments
- [\!important and CSS Custom Properties – Frontend Masters Blog](https://daily.dev/posts/important-and-css-custom-properties-frontend-masters-blog-xtx958jcd) · Frontend Masters · 2 upvotes · 0 comments

---

Tags: [#css](https://daily.dev/tags/css)

[View this post on daily.dev](https://daily.dev/posts/css-specificity-the-cascade-and-inheritance-explained-3ldecubog)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"CSS Specificity, the Cascade, and Inheritance Explained","url":"https://daily.dev/posts/css-specificity-the-cascade-and-inheritance-explained-3ldecubog","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/css-specificity-the-cascade-and-inheritance-explained-3ldecubog"},"datePublished":"2026-11-30T23:36:31.843Z","dateModified":"2026-11-30T23:36:51.538Z","description":"When several CSS rules set the same property on one element, the browser settles it one property at a time by asking three questions in order: which is more...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/84137e989b7eec43016c329bc0543633?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/84137e989b7eec43016c329bc0543633?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Kirupa","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Kirupa","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/ff2fdb4927d34b81bd07cd18d6049a98","url":"https://daily.dev/sources/kirupa"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/css-specificity-the-cascade-and-inheritance-explained-3ldecubog","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"css","timeRequired":"PT12M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Kirupa","item":"https://daily.dev/sources/kirupa"},{"@type":"ListItem","position":3,"name":"CSS Specificity, the Cascade, and Inheritance Explained"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/css-specificity-the-cascade-and-inheritance-explained-3ldecubog#faq","mainEntity":[{"@type":"Question","name":"Why does a single ID selector beat any number of class selectors in CSS?","acceptedAnswer":{"@type":"Answer","text":"Specificity is compared one column at a time: IDs first, then classes, then types. The columns never carry over into each other, so #intro at 1-0-0 beats .card .note:hover at 0-3-0. Even a selector with 11 classes can't outrank a single ID. It works like comparing version numbers rather than adding up totals. Developers untangling CSS conflicts keep their front-end fundamentals sharp on daily.dev."}},{"@type":"Question","name":"Why does a plain p rule override the color my paragraph inherits from a parent with a more specific selector?","acceptedAnswer":{"@type":"Answer","text":"An inherited value is the weakest thing in the cascade and has no specificity at all. A rule like #main { color: red } only matches the #main element itself, so paragraphs inside only inherit red. A p { color: gray } rule targets them directly, so it wins even though its selector is far less specific. If styles keep surprising you, daily.dev surfaces CSS debugging insights worth knowing."}},{"@type":"Question","name":"How do I debug a CSS rule that isn't applying in the browser?","acceptedAnswer":{"@type":"Answer","text":"Check that the selector matches, the declaration is valid, no rule wins on specificity or order, the rule isn't only styling a parent (so the element merely inherits), and no !important or inline style interferes. In the developer tools Styles panel, losing declarations are crossed out, and Chrome and Firefox show a selector's specificity on hover. Anyone chasing stubborn styling bugs will find daily.dev useful for web debugging practices."}}]}
```

