CKTIS / CSS
:not() — negation pseudo-class
The :not() pseudo-class selects elements that match none of the selectors in its argument list.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
:not(<complex-real-selector-list>):not() tests an element, rejecting it if it matches any argument. Its comma-separated list can contain complex selectors with combinators. li:not(.skip, [data-hidden]) is equivalent to li:not(.skip):not([data-hidden]) for matching, but not specificity.
The specificity of :not() equals that of its most specific argument; the pseudo-class adds no point itself. Pseudo-elements are forbidden, and an invalid argument invalidates the list. Selectors Level 3 allowed only one simple selector.
Negation neither removes elements nor automatically hides them. In the example, excluded elements retain the color from the li rule.
Examples
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>:not() example</title>
<style>
li { color: rgb(0, 0, 0); }
li:not(.skip, [data-hidden]) { color: rgb(0, 128, 0); }
</style>
<ul>
<li>Alpha</li>
<li class="skip">Beta</li>
<li data-hidden>Gamma</li>
<li>Delta</li>
</ul>
</html>Result
Alpha: rgb(0, 128, 0) Beta: rgb(0, 0, 0) Gamma: rgb(0, 0, 0) Delta: rgb(0, 128, 0)
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.