← All notes

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

Sources

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

Permanent ID: iil:note:jyfc8tp5

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.},
}

Markdown

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.

All artifact files (JSON index)

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.