CSS Specificity Order
Predict Output Beginner
Question
What color is the text?
Code
<style>
#my { color: red; }
.box { color: blue; }
p { color: green; }
</style>
<p id="my" class="box">Test</p>
Hint
ID selectors have the highest specificity.
Explanation
ID selectors (#my) have higher specificity than class (.box) and tag (p) selectors. So color: red wins. The specificity order is: inline > ID > class > tag. When specificity is equal, the last rule in the source wins. Use !important to override, but avoid it as it breaks the cascade.
Related Resources
Related Lessons
- CSS Selectors
Learn CSS selectors.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.