CSS: specificity table

CSS specifications provide a way to calculate the actual specificity of a selector by providing some numerical values as reference. Although this is a very useful method, it's somewhat difficult to remember, especially when dealing with multiple CSS selectors on large CSS files. For that reason, in this post I'm going to try to summarize the most common combinations of selectors in order to provide a visual memo that could be used later as a reminder.

CSS specificity table
RulesWinner
* {}
div {}
div {}
div {}
#test {}
#test {}
div {}
.test {}
.test {}
.test {}
#test {}
#test {}
div {}
body div {}
body div {}
div {}
body > div {}
body > div {}
.test {}
div[class="test"] {}
div[class="test"] {}
div {}
div:first-child {}
div:first-child {}
div {color: red !important;}
p {color: blue;}

div {color: red !important;}

This entry was posted in by Gabriele Romanato. Bookmark the permalink.

Comments are closed.