CSS :not() Pseudo Class

The :not() pseudo-class represents elements that do not match a list of selectors.

It is also known as the negation pseudo-class.

Version

CSS3

Syntax

:not() {
css declarations;
}

Example

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      p {
      color: #666;
      }
      :not(p) {
      color: #8ebf42;
      }
    </style>
  </head>
  <body>
    <h2>:not() selector example</h2>
    <p>Lorem Ipsum is simply dummy text</p>
    <p>Lorem Ipsum is simply dummy text</p>
    <div>Lorem Ipsum is simply dummy text</div>
    <a href="https://www.w3docs.com" target="_blank">Link to W3docs</a>
  </body>
</html>

Another example with the :not() selector:

Example

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      .text-blue{color:blue;}
      ul li:not(.text-blue) {
      color: #8ebf42;
      }
    </style>
  </head>
  <body>
    <h2>:not() selector example</h2>
    <ul>
      <li>List  item 1</li>
      <li class="text-blue">List  item 2</li>
      <li>List  item 3</li>
    </ul>
  </body>
</html>

Browser support

4.0+ 12.0+ 3.5+ 3.2+ 10.0+

Practice Your Knowledge

The :not() pseudo-class represents elements that




Related articles