You wrote the rule, DevTools shows it, and it is crossed out. Specificity is almost always why.
How it is scored
Think of three columns: IDs, classes/attributes/pseudo-classes, elements. #nav .item a is (1,1,1). Higher column wins; ties go to the later rule.
Things people get wrong
-
!importantand inline styles sit outside the normal scoring -
:where()has zero specificity;:is()takes its most specific argument - Universal selector
*adds nothing - Source order only matters after specificity ties
Practical rules
- Prefer single-class selectors (0,1,0)
- Avoid IDs for styling
- Use cascade layers (
@layer) so order beats specificity - Never fight specificity with
!important; lower the specificity of the rule you want to override
Check it
Paste a selector into the free CSS specificity calculator to see its score instantly. Runs fully in your browser.
More tools: webdevtoolbox.com.
Top comments (0)