MDN wants to talk to developers like you: https://qsurvey.mozilla.com/s3/8d22564490d8

Summary

The negation CSS pseudo-class, :not(X), has a functional notation taking a simple selector X as an argument. It matches elements that are not represented by the argument. X must not contain another negation selector.

Notes:
  • Useless selectors can be written using this pseudo-class. For example, :not(*) matches any element which is not any element, so the rule will never be applied.
  • It is possible to rewrite other rules. E.g., foo:not(bar) will match the same element as the simpler foo. Nevertheless the specificity of the first one is higher.
  • :not(foo) will match anything that isn't foo, including <html> and <body>.
  • This selector only applies to one element; you cannot use it to exclude all ancestors. For instance, body :not(table) a will still apply to links inside of a table, since <tr> will match with the :not() part of the selector.

Syntax

:not( <selector># )

Example

HTML

<p>This is a boring paragraph.</p>
<p class="classy">I am so very classy!</p>
<div>It ain't easy being green.</div>

CSS

.classy { text-shadow: 1px 1px 2px gold; }
p:not(.classy) { color: red; }
body :not(p) { color: green; }

Result

Specifications

Specification Status Comment
Selectors Level 4
The definition of ':not()' in that specification.
Working Draft Extends its argument to allow some non-simple selectors.
Selectors Level 3
The definition of ':not()' in that specification.
Recommendation Initial definition.

Browser compatibility

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0 (Yes) 1.0 (1.7 or earlier) 9.0 9.5 3.2
Extended arguments No support No support No support No support No support No support
Feature Android Edge Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support 2.1 (Yes) 1.0 (1) 9.0 10.0 3.2
Extended arguments No support No support No support No support No support No support