1. Skip to main content
        Home / CSS Almanac / Selectors / N / :not()

        The :not(X) property in CSS is a negation pseudo class and accepts a simple selector1 as an argument. Essentially, just another selector of any kind.

        :not matches an element that is not represented by the argument. The passed argument may not contain additional selectors or any pseudo-element selectors.

        See the Pen :not(X) by GRAY GHOST (@grayghostvisuals) on CodePen.

        /* the X argument can be replaced with any simple selectors */:not(X) {  property: value;}

        In this example we have an unordered list with a single class on the li:

        <ul>  <li></li>  <li class="different"></li>  <li></li></ul>

        Our CSS would select all the <li> elements except the one(s) with a class of .different.

        /* Style everything but the .different class */li:not(.different) {  font-size: 3em;}

        You could also do the same using pseudo classes which are considered a simple selector.

        p:not(:nth-child(2n+1)) {  font-size: 3em;}

        However if we use a pseudo element selector as our argument it will not produce the expected result.

        :not(::first-line) { /* ::first-line is a pseudo element selector and not a simple selector */  color: white;}
        Visual representation of the varied uses of :not()

        The specificity of the :not pseudo class is the specificity of its argument. The :not() pseudo class does not add to the selector specificity, unlike other pseudo-classes.

        Negations may not be nested so :not(:not(...)) is never permitted. Authors should also note that since pseudo elements are not considered a simple selector, they are not valid as an argument to :not(X). Be mindful when using attribute selectors as some are not widely supported as others. Chaining :not selectors with other :not selectors is permissible.

        Other Resources

        Browser Support

        ChromeSafariFirefoxOperaIEAndroidiOS
        14+4.0+3+11.1+9+2.1+3.0+

        1 A simple selector is classified as a Type Selector, Universal Selector, Attribute Selector, Class Selector, ID Selector, or Pseudo Class Selector.

            1. http://www.ilxs21.cn | http://m.ilxs21.cn | http://wap.ilxs21.cn | http://3g.ilxs21.cn | http://4g.ilxs21.cn | http://5g.ilxs21.cn | http://mobile.ilxs21.cn | http://vip.ilxs21.cn | http://ios.ilxs21.cn | http://anzhuo.ilxs21.cn | http://6ce51.ilxs21.cn | http://cb.ilxs21.cn | http://83fe1.ilxs21.cn | http://www.ilxs21.cn/dbc6.html | http://www.ilxs21.cn/c8bd.html | http://www.ilxs21.cn/37550c.html | 俄罗斯18tube 18young