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 › :not
not() - CSS - MDN Web Docs
If any selector passed to the :not() pseudo-class is invalid or not supported by the browser, the whole rule will be invalidated. The effective way to overcome this behavior is to use :is() pseudo-class, which accepts a forgiving selector list. For example :not(.foo, :invalid-pseudo-class) will invalidate a whole rule, but :not(:is(.foo, :invalid-pseudo-class)) will match any (including <html> and <body>) element that isn't .foo.
Discussions

html - :not selector in CSS - Stack Overflow
I want all text elements, except the ones in a c1 element, to be bold. I don't know in advance how many columns there can be. I've tried the following CSS that makes use of the :not selector, but it renders everything bold: More on stackoverflow.com
🌐 stackoverflow.com
html - Correct use of CSS :not selector for excluding element when in particular container - Stack Overflow
The styles are based on a design ... of- for example- h2 elements that must look different than other particular h2 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
Complex selector inside :not(), safe to use today?
Yeah we using them. More on reddit.com
🌐 r/css
20
4
September 24, 2024
🌐
W3Schools
w3schools.com › cssref › sel_not.php
CSS :not() Pseudo-class
accent-color align-content align-items ... ... More "Try it Yourself" examples below. The CSS :not() pseudo-class matches any element that is NOT the specified element/selector......
🌐
SamanthaMing
samanthaming.com › tidbits › 46-css-not-selector
CSS :not Selector | SamanthaMing.com
In the current version, you can only pass in simple selectors as your argument. However, in CSS Selectors Level 4, you will be able to pass in a list of selectors. So cool, right 👏. /* CSS Selectors Level 3 */ p:not(:first-of-type):not(.special) { } /* CSS Selectors Level 4 */ p:not(:first-of-type, .special) { }
🌐
GeeksforGeeks
geeksforgeeks.org › css › css-not-selector
CSS :not Selector - GeeksforGeeks
August 29, 2024 - This example demonstrates the usage of the :not selector to style all elements except paragraphs (<p>). ... <!DOCTYPE html> <html> <head> <title> CSS :not selector </title> <style> p { color: #000000; } :not(p) { color: green; } </style> </head> ...
🌐
Fjolt
fjolt.com › article › css-not-selector
A Complete Guide to How the CSS not Selector Works
August 6, 2022 - Here’s another example. By default, all elements will have the Arial font - except for .old-fashioned elements: <div class="old-fashioned">Old Fashioned Text</div> <div>Some Text</div> Our CSS, where only non .old-fashioned elements use the Arial font, looks like this: div:not(.old-fashioned) { font-family: Arial, sans-serif; } You might be familiar with the concept of specificity in CSS, where certain selectors “override” others.
🌐
Daily Dev Tips
daily-dev-tips.com › posts › css-not-selector
CSS not selector (:not) Tutorial 2022 - Daily Dev Tips
November 30, 2020 - For this demo we will make a simple list which we will style with CSS and the not selector. <ul> <li class="new">Text rule 1</li> <li id="not_me">Text rule 2</li> <li>Text rule 3</li> <li>Text rule 4</li> <li>Text rule 5</li> </ul> ... I hope these code examples give you a good overview of just how powerful the :not selector in CSS can be for your website.
Find elsewhere
🌐
DEV Community
dev.to › ayoazeez26 › the-css-not-selector-4jaf
The CSS :not() Selector - DEV Community
June 26, 2020 - For example, the following will add a box shadow and a background color to all buttons that do not contain the plump class when they are being hovered on. You can also use the tag :not() selector globally in the sense that you are not applying ...
🌐
Codrops
tympanus.net › codrops › css_reference › not
:not() | Codrops
February 3, 2015 - So, this rule: li:not(.new) { /* style all list items except the ones that have the class new */ } will select all list items except those that have a class name .new. The :not() selector is chainable with more :not() selectors. For example, the following will match all articles except the one with an ID #featured, and then will filter out the articles with a class name ...
🌐
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 as an argument.
🌐
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 ...
🌐
OpenReplay
blog.openreplay.com › selective-styling-in-css-with-the-not-pseudoclass
Selective Styling in CSS with the :not Pseudo-class
February 20, 2024 - The CSS styles enclosed within curly braces ({ /* Styles to be applied */ }) will be applied to the elements that match the selector but not the ones specified in the :not pseudo-class. Let’s consider a scenario where you have a navigation menu and want to style all list items (li elements) in the menu except for those with a specific class, let’s say “inactive.” You can use the :not pseudo-class to achieve this. Here’s an elaborate example...
🌐
GeeksforGeeks
geeksforgeeks.org › css › how-to-select-elements-not-having-a-certain-class-or-attribute-in-css
How to select elements not having a certain class or attribute in CSS ? - GeeksforGeeks
August 5, 2025 - The content in these paragraphs that does not have the 'notHighlight' class is bolded according to the CSS rule. Example: In this example, we are going to highlight the 'p' tag except having the class as 'notHighlight' using :not() selector.
🌐
W3docs
w3docs.com › learn-css › not.html
CSS :not() Pseudo Class - Lean CSS | W3Docs
The:not(.foo) matches anything that isn't .foo, (including <html> and <body>). The :not selector only applies to one element.
🌐
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 - All about the :not() selector As CSS grows and grows, more robust and useful selectors are adopted into the spec. Although I don’t know all them by heart, I regularly use (in production) widely …
🌐
DEV Community
dev.to › braydoncoyer › the-powerful-css-not-selector-20fg
The Powerful CSS not Selector - DEV Community
March 29, 2022 - The :not() CSS selector is a powerful addition to the pseudo-class toolbelt, allowing you to select elements that are omitted by its argument. Here’s an example. I have a few classes set up - one applies base styles for all buttons, one sets ...
🌐
W3Schools
w3schools.am › cssref › sel_not.html
CSS :not Selector
The :not(selector) selector matches every element that is NOT the specified element/selector. The numbers in the table specifies the first browser version that fully supports the selector. ... Tabs Dropdowns Accordions Side Navigation Top Navigation Modal Boxes Progress Bars Parallax Login ...
🌐
DEV Community
dev.to › samanthaming › css-not-selector-ek2
CSS :not Selector - DEV Community
February 4, 2019 - Instead of using 2 different selectors to assign styling and then another to negate it. Use the :not selector for more precise selection…. Tagged with css, webdev, beginners, devtips.