Typically you add a class selector to the :not() pseudo-class like so:

:not(.printable) {
    /* Styles */
}

:not([attribute]) {
    /* Styles */
}

But if you need better browser support (IE8 and older don't support :not()), you're probably better off creating style rules for elements that do have the "printable" class. If even that isn't feasible despite what you say about your actual markup, you may have to work your markup around that limitation.

Keep in mind that, depending on the properties you're setting in this rule, some of them may either be inherited by descendants that are .printable, or otherwise affect them one way or another. For example, although display is not inherited, setting display: none on a :not(.printable) will prevent it and all of its descendants from displaying, since it removes the element and its subtree from layout completely. You can often get around this by using visibility: hidden instead which will allow visible descendants to show, but the hidden elements will still affect layout as they originally did. In short, just be careful.

Answer from BoltClock on Stack Overflow
Top answer
1 of 10
1346

Typically you add a class selector to the :not() pseudo-class like so:

:not(.printable) {
    /* Styles */
}

:not([attribute]) {
    /* Styles */
}

But if you need better browser support (IE8 and older don't support :not()), you're probably better off creating style rules for elements that do have the "printable" class. If even that isn't feasible despite what you say about your actual markup, you may have to work your markup around that limitation.

Keep in mind that, depending on the properties you're setting in this rule, some of them may either be inherited by descendants that are .printable, or otherwise affect them one way or another. For example, although display is not inherited, setting display: none on a :not(.printable) will prevent it and all of its descendants from displaying, since it removes the element and its subtree from layout completely. You can often get around this by using visibility: hidden instead which will allow visible descendants to show, but the hidden elements will still affect layout as they originally did. In short, just be careful.

2 of 10
255
:not([class])

Actually, this will select anything that does not have a css class (class="css-selector") applied to it.

I made a jsfiddle demo

    h2 {color:#fff}
    :not([class]) {color:red;background-color:blue}
    .fake-class {color:green}
    <h2 class="fake-class">fake-class will be green</h2>
    <h2 class="">empty class SHOULD be white</h2>
    <h2>no class should be red</h2>
    <h2 class="fake-clas2s">fake-class2 SHOULD be white</h2>
    <h2 class="">empty class2 SHOULD be white</h2>
    <h2>no class2 SHOULD be red</h2>

Is this supported? Yes : Caniuse.com (accessed 02 Jan 2020):

  • Support: 98.74%
  • Partial support: 0.1%
  • Total:98.84%

Funny edit, I was Googling for the opposite of :not. CSS negation?

selector[class]  /* the oposite of :not[]*/
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS › Reference › Selectors › :not
not() - CSS - MDN Web Docs
December 16, 2025 - The :not() CSS pseudo-class represents elements that do not match a list of selectors. Since it prevents specific items from being selected, it is known as the negation pseudo-class.
Discussions

html - Correct use of CSS :not selector for excluding element when in particular container - Stack Overflow
The styles are based on a design ... elements in order for the design to be adhered to. Currently, I am trying to apply some styling that should affect most h2 elements, but not h2 elements which appear within a div with the class "block". How would the CSS selector look in this ... More on stackoverflow.com
🌐 stackoverflow.com
"CSS id selector `x` not found."
If the code is running fine its probably not a syntax error. Are you using any older CSS linting or syntax checkers? Check if it gets removed if ur selector uses camel case naming convention More on reddit.com
🌐 r/vscode
3
7
December 29, 2020
Why my class selector wont work? i stayed literally 40min trying everything
Just do .header__container { max-width: 1057px; margin: 0 auto; } More on reddit.com
🌐 r/css
25
6
August 1, 2022
CSS Selector :not() - not working in querySelector
Without looking it up, are you able to tell me what .querySelector() does? I believe your issue is with the method, not the selector. More on reddit.com
🌐 r/learnjavascript
5
1
August 22, 2022
🌐
W3Schools
w3schools.com › cssref › sel_not.php
CSS :not() Pseudo-class
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT SWIFT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING HTML & CSS BASH RUST TOOLS · CSS Reference CSS Browser Support CSS Selectors CSS Combinators CSS Pseudo-classes CSS Pseudo-elements CSS At-rules CSS Functions CSS Reference Aural CSS Web Safe Fonts CSS Fallback Fonts CSS Animatable CSS Units CSS PX-EM Converter CSS Colors CSS Color Values CSS Default Values CSS Entities
🌐
CSS-Tricks
css-tricks.com › almanac › pseudo-selectors › n › not
:not | CSS-Tricks
September 13, 2024 - The :not() property in CSS is a negation pseudo class and accepts a simple selector or a selector list as an argument. It matches an element that is not
🌐
Polypane
polypane.app › blog › decoding-css-selectors-has-not-vs-not-has
Decoding CSS Selectors: :has(:not) vs :not(:has) | Polypane
February 18, 2025 - If you use :has(), then the selector you put inside of it is already applied to the child elements of the element you're selecting. This is different from :is() and :not(), which are applied to the element itself.
🌐
GeeksforGeeks
geeksforgeeks.org › css › css-not-selector
CSS :not Selector - GeeksforGeeks
August 29, 2024 - The CSS :not selector is used for excluding specific elements from a selection, allowing for more refined and targeted styling. By leveraging this pseudo-class, developers can create sophisticated stylesheets that apply rules conditionally.
🌐
Mozilla
developer.mozilla.org › en-US › blog › css-not-pseudo-multiple-selectors
How :not() chains multiple selectors - MDN Web Docs - Mozilla
Have you ever wanted to apply styles to only a few elements and exclude everything else? This is possible in CSS by using the :not() pseudo-class. In this post, we'll take brief look at CSS pseudo-classes, how the :not() pseudo-class works, and how it behaves when multiple selectors are passed ...
Find elsewhere
🌐
Go Make Things
gomakethings.com › the-css-not-pseudo-selector
The css :not() pseudo-selector | Go Make Things
I was working on a side-project this weekend, and the :not() pseudo-selector made my life a lot easier! The :not() pseudo-selector lets you select elements, but exclude ones that match an additional set of selectors. Pass in the selectors to ...
🌐
SitePoint
sitepoint.com › blog › css › css pseudo-classes: :not() and :target
CSS Pseudo-classes: :not() and :target — SitePoint
November 6, 2024 - The :not() pseudo-class selects all elements except those that match the specified selector, while the :target pseudo-class allows highlighting of the portion of the document that corresponds to a specific URL fragment.
🌐
SamanthaMing
samanthaming.com › tidbits › 46-css-not-selector
CSS :not Selector | SamanthaMing.com
Instead of using 2 different selectors to assign styling and then another to negate it. Use the :not selector for more precise selection...
🌐
W3C
w3.org › wiki › CSS › Selectors › pseudo-classes › :not
CSS/Selectors/pseudo-classes/:not - W3C Wiki
September 26, 2011 - The following selector matches all p elements in an HTML document that are not "#example"(value of id attribute): [style.css] p:not(#example){ background-color: yellow; } [index.html] <body> <h1>:not example</h1> <p>This is a paragraph.</p> <p id="example">This is a paragraph.</p> <p>This is a paragraph.</p> </body> The following selector matches all input elements in an HTML document that are not disabled: [style.css] input:not([DISABLED]){ background-color: yellow; } [index.html] <body> <form> Phone: <input type="tel"><br> E-mail: <input type="email" disabled="disabled"> </form> </body> CSS defines the :not pseudo-class selector in 6.6.7.
🌐
Medium
medium.com › @dave_lunny › all-about-the-not-selector-4c9ab01819e4
All about the :not() selector. Everything you ever needed to know… | by Dave Lunny | Medium
January 10, 2017 - By far the best & most powerful selector I have learned about in the past few months is CSS3's :not() selector.
🌐
Manuel Matuzovic
matuzo.at › blog › 2022 › 100daysof-day50
Day 50: :has(:not()) vs. :not(:has()) - Manuel Matuzovic
December 2, 2022 - That's because .card:has(:not(img)) means “select a .card that has any element that is not an image”. This means that the selector only wouldn't apply if the card only contained images. <div class="card"> <img src="https://assets.codepen.io/144736/skateboard.jpg" alt="" /> </div> If we switch :has() and :not() we're instructing the browser to do something completely different.
🌐
Fjolt
fjolt.com › article › css-not-selector
A Complete Guide to How the CSS not Selector Works
August 6, 2022 - For example, a class has a lower specificity than an id, so any id CSS properties will override class properties on the same element. The :not selector also affects specificity. For example, if you had div:not(#id) in your code, it still counts as having an id, so the specificity increases as if it has an id.
🌐
Codrops
tympanus.net › codrops › css_reference › not
:not() | Codrops
February 3, 2015 - :not() is a CSS negation pseudo-class selector. It is a functional pseudo-class selector that takes a simple selector as
🌐
Can I Use
caniuse.com › css-not-sel-list
selector list argument of :not() | Can I use... Support tables for HTML5, CSS3, etc
Selectors Level 3 only allowed :not() pseudo-class to accept a single simple selector, which the element must not match any of. Thus, :not(a, .b, [c]) or :not(a.b[c]) did not work. Selectors Level 4 allows :not() to accept a list of selectors. Thus, :not(a):not(.b):not([c]) can instead be written ...
🌐
W3docs
w3docs.com › learn-css › not.html
CSS :not() Pseudo Class - Lean CSS | W3Docs
The :not() CSS pseudo-class selects and styles the elements that do not match a list of selectors. Read more about the pseudo-class and try examples.
🌐
CSS-Tricks
css-tricks.com › css-not-with-multiple-classes
CSS :not() with Multiple Classes | CSS-Tricks
July 22, 2019 - The :not() selector doesn’t add any specificy by itself, but what is inside does, so :not(.foo) adds the same weight as .foo does.
🌐
DEV Community
dev.to › dailydevtips1 › css-not-selector-5dib
CSS :not selector - DEV Community
November 30, 2020 - The CSS :not selector is really cool we can call this a negation pseudo-class selector. A mouth-full... Tagged with css.