CSS Specificity

Emma Wedekind ✨ on January 21, 2019

CSS Specificity is the set of the rules applied to CSS selectors in order to determine which style is applied to an element. The more specific a ... [Read Full]
markdown guide

This was a super cool read! Especially the calculation at the end – that was definitely something I knew would work, but never knew why. Thanks for a great explanation.

Also, I love the effort you put into your section headers, etc. The yellow is really lovely, and that attention to visual detail isn't something you see a lot in other blogs :)


Interesting point you make about Bootstrap and !important. I always hate writing !important (when you write !important, a kitten dies), but Bootstrap doesn't leave you much choice sometimes. Great article, very well explained.


Cool article, thanks Emma!

Didn't know there was a formula to calculate specificity nor tools to aid. They might be handy when you're trying to debug :)

You may run into situations when leveraging CSS frameworks, such as Bootstrap, where you can't use CSS specificity to override the native styles. In these instances, using !important is not considered bad practice.

Bootstrap is the main reason we use !important :D Fortunately I see less and less Bootstrap around.


Personally I'm a big fan of Bootstrap 4 grid, since they use flexbox.

But regarding the Bootstrap overrides, don't override it with !important.
Customise it by overriding the sass variables instead of styles for every component. A good example is bootswatch.com.


Hi, Emma!
Thank you for this great article, it helped me greatly;

Look at the screenshoot, it seems to me it doesn't work properly;

combinator selector > selects li elements that are direct children of an element of that id.

Check this 😉



Quick check ;-)


I think using !important is always ALWAYS a bed practice.
Sometimes you have no other choince but at least try before.


I posted this in tonight's DevDiscuss on Twitter, but thought it would be helpful to leave this in the comments of your post as well.


Thank you very much for this article!
I knew that “CSS specificity” was a thing but I never knew that there was such a (mathematically) simple calculation rule.


The Star Wars one cracks me up. I saw it again for the first time in a while a couple of weeks ago and was 😂.


This is the most succinct article I have ever seen on specificity. I love the use of graphics for calculating specificity. Excellent job!


I knew about this already, but it's nice to have something to reference anyway, especially when it's this short and sweet.


Thanks that was the most clear explanation of CSS specificity I have come through.


I didn't know about specifity in CSS, It was nice to learned it in such a practical and math-fun way, thank you Emma!


The best kind of article! Thank you for the clear explanation!


Thank you for this article, was so great!! I'll start using the four-category system.


Really awesome read. I've spent hours before now trying to override styles in WordPress templates (made by other people) and it's been brutal.

code of conduct - report abuse