Video tutorialTrack course · freeCodeCamp
Speed
Transcript & captions
9/9
When two rules target the same element, the winner is decided by specificity, then by source order. Specificity is counted as (inline, id, class/attribute/pseudo-class, element).
- Inline style = 1,0,0,0
- #id = 0,1,0,0
- .class, [attr], :hover = 0,0,1,0
- div, p, ::before = 0,0,0,1
- !important overrides everything — use it as a last resort.
Try it yourself
Knowledge check
0/1 answeredWhich selector has the highest specificity?