How do :is(), :where(), and :not() affect selector specificity?
Quick answer
:is() and :not() take the specificity of their most specific argument; the functions themselves add no separate pseudo-class weight. :where() and every argument inside it contribute zero specificity. Use :where() when you want a precise target that stays easier to override. Specificity is considered only after cascade origin and importance, and within the relevant layer. [S1]
The question, the details, the next step.
A practical checklist
List the arguments inside each
:is(),:where(), or:not().For
:is()and:not(), identify the most specific argument; it determines the function’s contribution. [S1]For
:where(), count the function and all its arguments as zero specificity. [S1]Remember that selector parts outside these functions still contribute their own specificity.
Before changing a selector, check cascade origin, importance, and the relevant layer. [S1]
Prefer
:where()when you want grouped targets without added specificity from the grouping.
A few more useful answers
Does `:not()` always have low specificity because it excludes something?
No. Its most specific argument determines its contribution, and the function itself adds no separate pseudo-class weight. [S1]
Does `:where()` make every declaration using it win?
No. It contributes zero specificity, but specificity is considered after cascade origin and importance, and within the relevant layer. [S1]
Do these examples give numeric specificity tuples?
No. They show how each function contributes: :is() and :not() take the most specific argument’s specificity, while :where() and its arguments contribute zero. [S1]
Sources
References used for this guide.
- [S1] Specificity — MDN developer.mozilla.org · Checked
