:is() and :where() Take Entire Selectors a:is(body.home #logo) { /* … */ }a:where(body.home #logo) { /* … */ }
/* (a) AND ALSO (nav .active) */a:where(nav .active) { color: black; }a:is(nav .active) { color: black; }
/* (h1 a) AND ALSO (main > *) */h1 a:where(main > *) { color: black; }h1 a:is(main > *) { color: black; }
h1 a:hover, h1 a:focus,h2 a:hover, h2 a:focus,h3 a:hover, h3 a:focus,h4 a:hover, h4 a:focus,h5 a:hover, h5 a:focus { text-decoration: underline;}
Commas for OR /* (h1 OR h2 OR …) AND (a:hover OR a:focus) */:is(h1, h2, h3, h4, h5) a:where(:hover, :focus) { text-decoration: underline;}
Example From User Agent table[rules=cols i] > tfoot > tr > td,table[rules=cols i] > tfoot > tr > th,table[rules=all i] > tfoot > tr > td,table[rules=all i] > tfoot > tr > th { /* … */}
Use :where() To Remove Specificity a { color: blue; }a:hover { color: rebeccapurple; }nav a.active { color: black; }
But is() takes specificity From Highest Internal Selector :is(a, .b, #c .d) { /* 1,1,0 */ }a:is(.b, #c .d) { /* 1,1,1 */ }
Comparing Specificity a:where(#logo, .sponsor .logo) { /* specificity: 0,0,1 */}a:is(#logo, .sponsor .logo) { /* specificity: 1,0,1 */}
It doesn’t matter Which Item Matches! a:is(#logo, .sponsor .logo) { /* … */ } <a class="sponsor logo">Still 1,0,1</a>
Use :not() For Excluding Elements (inside matches are removed from outside matches) /* (p) UNLESS (.warning) */p:not(.warning) { /* … */ }
New :has() Selector form:has(:focus) { /* form:focus-within */ }button:has(svg) { /* icon button */ }.card:has(> figure:first-child) { /* image card */ }.card:not(:has(img)) { /* card without image */ }input:has(+ .error) { /* input followed by error */ }
button, .btn { background: rebeccapurple; color: white; &:focus, &:hover, &:active { background: teal; }}
button, .btn { /* … */ }:is(button, .btn):focus,:is(button, .btn):hover,:is(button, .btn):active { /* … */ }
.card { @layer defaults { display: flex; } @layer variations { @media (min-width: 30em) { display: grid; } }}
@scope (.light-theme) { a { /* similar to simple nesting… */ }}@scope (.dark-theme) { a { /* but the _closer_ scope root wins… */ }}
<article> <style scoped> p { color: green; } </style> <p>This paragraph will be green.</p></article><p>This paragraph won't!</p>
<article> <style> @scope { p { color: green; } } </style> <p>This paragraph will be green.</p></article><p>This paragraph won't!</p>