When several rules set the same property on an element, the browser uses specificity to decide which wins. From strongest to weakest:
Inline styles (style="...")
Id selectors (#nav)
Classes, attributes and pseudo-classes (.menu, [type], :hover)
Elements and pseudo-elements (p, ::before)
If two rules have equal specificity, the one written last wins.
!important overrides everything, but it makes CSS hard to maintain. Avoid it except as a last resort.
💡 Key Takeaways: CSS Specificity
Mastering CSS Specificity helps you write clean and reliable CSS code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.