0-0-0: Global selector0-0-1: Type Selector (Elements & pseudoelements)0-1-0: Class selector (Also attribute selector & pseudoclass)1-0-0: ID selector
1-0-0-0: inline styles1-0-0-0-0:!important
(on value)
Estelle Weyl | @estellevw | Github | Press → key to advance.
0-0-0: Global selector0-0-1: Type Selector (Elements & pseudoelements)0-1-0: Class selector (Also attribute selector & pseudoclass)1-0-0: ID selector1-0-0-0: inline styles1-0-0-0-0:
!important(on value)
<body class="blue" id="myPage">
<div id="someId">
<article class="home">
<p class="important">
<a href="index.html" class="classy" id="anotherID">
Link
</a>
</p>
</article>
</div>
</body>
body.blue div#someId a#otherId.classy {
color: blue; }
#myPage #someId article.home p.important a {
color: red; }
body.blue div#someId a#otherId.classy {
color: blue; }
#myPage #someId article.home p.important a {
color: red; }
2-X-X X-2-X X-X-3
The * selector, or global selector, has a specifity of 0.
Combinators, like ~, >, spaces, and + have no value
ul li {} 0-0-2
ul > li {} 0-0-2
:not has no value, but parameter selector does
.myClass:not(p) {} 0-1-1
Specificity is not inheritance
p#myP.important {
color: red !important;
}
a {
color: purple;
}
<p class="important" id="myP">Paragraph with a <a href="x.html">link</a></p>
Paragraph with a link
Styles for a directly targeted element take precedence over inherited styles regardless of inherited specificity.
:not(a, .b, #c)
:not(a, .b, #c)
:is(a, .b, #c)
:where(a, .b, #c)
:nth-child(-n + 3 of a.b#c) /* 1-2-1 */
.disabled {cursor: default !important;}
p.btn {cursor: pointer;}
v.
.disabled.disabled.disabled {cursor: default;}
p.btn {cursor: pointer;}
#TheirWidget {background-color: blue !important;}
#3rdPartyWidget {background-color: white;}
v.
#TheirWidget#TheirWidget {background-color: blue ;}
#3rdPartyWidget {background-color: white;}
a:not(#idDoesNotExist#idDoesNotExist#idDoesNotExist)
When multiple declarations have equal specificity, the last declaration found in the CSS is applied to the element.
There are extensions that enable you to see the weight of a selectors. But, by default, you can inspect which property value has won out and which selectors lost the specifity battle in the computed section in DevTools, but the selectors are ordered in specifity order.