CSS Cascade Layers Vs. BEM Vs. Utility Classes: Specificity Control<\/h1>\nVictor Ayomipo<\/address>\n 2025-06-19T15:00:00+00:00
\n 2025-06-19T20:32:57+00:00
\n <\/header>\n
CSS is wild, really wild. And tricky. But let\u2019s talk specifically about specificity<\/strong>.<\/p>\nWhen writing CSS, it\u2019s close to impossible that you haven\u2019t faced the frustration of styles not applying as expected — that\u2019s specificity. You applied a style, it worked, and later, you try to override it with a different style and\u2026 nothing, it just ignores you. Again, specificity.<\/p>\n
Sure, there\u2019s the option of resorting to !important<\/code> flags, but like all developers before us, it\u2019s always risky and discouraged<\/a>. It\u2019s way better to fully understand specificity than go down that route because otherwise you wind up fighting your own important styles.<\/p>\nSpecificity 101<\/h2>\n
Lots of developers understand the concept of specificity in different ways.<\/p>\n
The core idea of specificity is that the CSS Cascade algorithm used by browsers determines which style declaration is applied when two or more rules match the same element.<\/p><\/blockquote>\n
Think about it. As a project expands, so do the specificity challenges. Let\u2019s say Developer A adds .cart-button<\/code>, then maybe the button style looks good to be used on the sidebar, but with a little tweak. Then, later, Developer B adds .cart-button .sidebar<\/code>, and from there, any future changes applied to .cart-button<\/code> might get overridden by .cart-button .sidebar<\/code>, and just like that, the specificity war begins.<\/p>\n<\/p>\n
\n 2025-06-19T20:32:57+00:00
\n <\/header>\n
When writing CSS, it\u2019s close to impossible that you haven\u2019t faced the frustration of styles not applying as expected — that\u2019s specificity. You applied a style, it worked, and later, you try to override it with a different style and\u2026 nothing, it just ignores you. Again, specificity.<\/p>\n
Sure, there\u2019s the option of resorting to Lots of developers understand the concept of specificity in different ways.<\/p>\n The core idea of specificity is that the CSS Cascade algorithm used by browsers determines which style declaration is applied when two or more rules match the same element.<\/p><\/blockquote>\n Think about it. As a project expands, so do the specificity challenges. Let\u2019s say Developer A adds !important<\/code> flags, but like all developers before us, it\u2019s always risky and discouraged<\/a>. It\u2019s way better to fully understand specificity than go down that route because otherwise you wind up fighting your own important styles.<\/p>\n
Specificity 101<\/h2>\n
.cart-button<\/code>, then maybe the button style looks good to be used on the sidebar, but with a little tweak. Then, later, Developer B adds
.cart-button .sidebar<\/code>, and from there, any future changes applied to
.cart-button<\/code> might get overridden by
.cart-button .sidebar<\/code>, and just like that, the specificity war begins.<\/p>\n