🌐CSS Specificity
Also known as Specificity, Selector Specificity, CSS Specificity Rules
The score that picks which CSS rule wins. It counts when two rules hit one part.
Think of it like
It is like a game of cards where a king beats any number of jacks.
Example
Emma sets .note to blue, but the text stays red. A rule with #intro .note scores higher, so it wins until she changes it.
Why it matters
It explains the most common CSS puzzle: a style you wrote that does nothing. Low scores keep styles easy to change.
Definition
Example code
css
p { color: black; } /* 0-0-1 */
.note { color: blue; } /* 0-1-0 */
#intro p { color: red; } /* 1-0-1, wins */Common mistake
Key takeaways
- 1Three counts. IDs, then classes, then tags.
- 2Left column first. One ID beats any number of classes.
- 3Ties go last. The later rule wins a tie.