CSS specificity: how competing selectors are scored
Answer: Specificity is a cascade stage that scores competing CSS rules. The score is a triad of A, B, and C, not a decimal number. The highest-specificity rule wins. Keep scores only as high as you need.
The specificity triad
Specificity is one distinct stage of the cascade.
A, B, and C form a triad, not a decimal number.
A is id-like, B is class-like, and C is element-like, often in (A,B,C) notation.
Declarations from rules with the highest specificity win.
How selectors add points
The triad starts at (0,0,0). A universal selector adds no specificity.
An element or pseudo-element increments C by 1, so div is (0,0,1).
A class, pseudo-class, or attribute selector increments B by 1.
#myID increments A by 1 and scores (1,0,0), unlike the [id="myID"] form.
The :not() and :is() pseudo-classes do not themselves add to the specificity calculation. :where() always has a specificity of (0,0,0).
A style attribute does not affect specificity, and neither does !important, which only changes origin.
When layers outrank a selector score
The @layer rule adds cascade layers that can prevent specificity conflicts.
With layered styles, layer precedence always beats selector specificity.
Layered styles create new cascade planes.
See also
Claims
- id: C1 claim: Declarations from rules with the highest specificity win. source: S1 evidence: "Declarations from rules with the highest specificity win"
- id: C2 claim: The specificity score is a triad of components A, B, and C. source: S1 evidence: "a triad that consists of three components"
- id: C3 claim: A universal selector adds no specificity. source: S1 evidence: "adds no specificity"
- id: C4 claim: The :where() pseudo-class always scores (0,0,0). source: S1 evidence: "always has a specificity of (0,0,0)"
- id: C5 claim: The precedence of a layer beats the specificity of a selector. source: S2 evidence: "the precedence of a layer always beats the specificity of a selector"
Sources
- [S1] Specificity. web.dev. https://web.dev/learn/css/specificity . License: CC-BY-4.0. Accessed 2026-11-23.
- [S2] Cascade layers are coming to your browser. Chrome Developers. https://developer.chrome.com/blog/cascade-layers . License: CC-BY-4.0. Accessed 2026-11-23.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: web.dev, Specificity; Chrome Developers, Cascade layers are coming to your browser. CC-BY-4.0 (https://web.dev/learn/css/flexbox). Copyright Google LLC. web.dev text is CC BY 4.0. CC-BY-4.0 (https://developers.google.com/site-policies). Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License. Copyright Google LLC. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: web.dev, Specificity; Chrome Developers, Cascade layers are coming to your browser. CC-BY-4.0 (https://web.dev/learn/css/flexbox). Copyright Google LLC. web.dev text is CC BY 4.0. CC-BY-4.0 (https://developers.google.com/site-policies). Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License. Copyright Google LLC.
Cite this
iinventedlight. 2026. "CSS specificity: how competing selectors are scored." iinventedlight Library, iil:note:jyfc8tp5, version of 2026-11-23. https://iinventedlight.com/library/notes/css-specificity/. License: CC-BY-4.0.
@misc{iil_note_jyfc8tp5,
author = {{iinventedlight}},
title = {{CSS specificity: how competing selectors are scored}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-23},
url = {https://iinventedlight.com/library/notes/css-specificity/},
note = {Permanent ID iil:note:jyfc8tp5. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- css-specificity.schema.json (schema; CC-BY-4.0)
- css-specificity.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/css-specificity.md.