There is now a CSS Nesting Module in the CSS specification. The module is currently a Working Draft and CSS nesting is supported in all major browsers.

The syntax looks like this:

table.colortable {
  & td {
    text-align:center;
    &.c { text-transform:uppercase }
    &:first-child, &:first-child + td { border:1px solid black }
  }
  & th {
    text-align:center;
    background:black;
    color:white;
  }
}

.foo {
  color: red;
  @nest & > .bar {
    color: blue;
  }
}

.foo {
  color: red;
  @nest .parent & {
    color: blue;
  }
}
Answer from etoxin on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS › Reference › Selectors › Nesting_selector
& nesting selector - CSS | MDN
December 16, 2025 - The CSS & nesting selector explicitly states the relationship between parent and child rules when using CSS nesting. It makes the nested child rule selectors relative to the parent element. Without the & nesting selector, the child rule selector selects child elements.
🌐
W3Schools
w3schools.com › cssref › sel_nesting.php
CSS Nesting (&) Selector
The CSS nesting (&) selector is used to apply styles for an element within the context of another element.
Discussions

CSS nesting: use with caution
If you're going deeper than 2 levels in nesting, you should rethink what you're doing. Inheritance is a bitch. More on reddit.com
🌐 r/css
46
10
February 13, 2025
css selectors - Nesting CSS classes - Stack Overflow
It’s translated to well-formatted, standard CSS using the command line tool or a web-framework plugin. ... Rather than constructing long selector names to specify inheritance, in Less you can simply nest selectors inside other selectors. More on stackoverflow.com
🌐 stackoverflow.com
Begginer question: nested css or classes
What if you want to add another div inside the container that should not be a flexbox? Your approach will get pretty messy pretty fast. More on reddit.com
🌐 r/webdev
76
54
April 17, 2024
nesting inside css :not() selectors - Stack Overflow
Is it possible to have nested values inside the :not selector? For eg: :not(div > div) Whenever I tried it, it does not seem to work. Perhaps you need to use it another way which I have not fi... More on stackoverflow.com
🌐 stackoverflow.com
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS › Guides › Nesting › Using
Using CSS nesting - CSS | MDN
November 7, 2025 - In the CSS code below, nesting is used to create compound selectors both with and without &. The top-level selector defines the basic styles for elements with class="notice". The & nesting selector is then used to create compound selectors for elements with either class="notice warning" or ...
🌐
web.dev
web.dev › learn › css › nesting
Nesting - CSS
August 21, 2025 - Since the & selector can't represent pseudo-elements, the nested border styles will only apply to the blockquote. When making compound selectors using & and type selectors, the type selector must go first without any whitespace between. /* valid css nesting */ .feature { p& { font-weight: bold; } } /* invalid css nesting */ .feature { &p { font-weight: bold; } }
🌐
Reddit
reddit.com › r/css › css nesting: use with caution
r/css on Reddit: CSS nesting: use with caution
February 13, 2025 - I like to nest media queries and pseudo-classes/elements, that's it. ... You can also use it for `@supports` and some other `@at-rules` which is pretty cool! ... Didn't know you can put them inside selectors. ... You can, which is pretty convenient! ... Atomic CSS because while working as a ...
🌐
Piccalilli
piccalil.li › blog › css-nesting-use-with-caution
CSS nesting: use with caution - Piccalilli
January 30, 2025 - Native CSS also has a nesting selector — & — which you would think works in near-enough the same was as Sass, but that’s not strictly true.
🌐
W3C
w3.org › TR › css-nesting-1
CSS Nesting Module Level 1
January 22, 2026 - This module introduces the ability to nest one style rule inside another, with the selector of the child rule relative to the selector of the parent rule. This increases the modularity and maintainability of CSS stylesheets.
Find elsewhere
🌐
Chrome Developers
developer.chrome.com › docs › css-ui › css-nesting
CSS Nesting | Chrome for Developers
March 8, 2023 - CSS nesting allows you to define styles for an element within the context of another selector.
🌐
Reddit
reddit.com › r/webdev › begginer question: nested css or classes
r/webdev on Reddit: Begginer question: nested css or classes
April 17, 2024 - If you need to override a css rule from somewhere else then you nest, because nesting increases specificity. However you don’t need nesting to do this, you just write out the selector with multiple classes in a row.
🌐
DEV Community
dev.to › mechcloud_academy › css-nesting-and-its-potential-to-replace-css-preprocessors-like-scss-and-sass-1l74
CSS Nesting and Its Potential to Replace CSS Preprocessors Like SCSS and SASS - DEV Community
June 19, 2025 - CSS nesting is a native CSS feature that allows you to nest selectors within one another, creating a hierarchical structure that mirrors the HTML document. This eliminates the need to repeat parent selectors, making stylesheets more concise ...
Top answer
1 of 2
21

:not() only accepts one simple selector at a time; this is mentioned in the Selectors 3 spec:

The negation pseudo-class, :not(X), is a functional notation taking a simple selector (excluding the negation pseudo-class itself) as an argument. It represents an element that is not represented by its argument.

The simple selectors in your example would be the two div tokens that you have. Other simple selectors include class selectors, ID selectors, attribute selectors and pseudo-classes. It does not accept more than one simple selector, nor does it accept combinators like > or space.

Depending on which elements you're trying to select exactly, there may not be a way to exclude div > div:

  • If you only want to select elements that are children of a div, that are themselves not div, use this instead:

    div > :not(div)
    
  • If you only want to select div elements whose parent element is not a div, use this instead:

    :not(div) > div
    

If you want to use this negation by itself, selecting all other elements, then there isn't a way using just a selector.

The only other viable workaround in CSS that I can think of is to apply styles to the elements you want without the :not() expression, then undo them for div > div. This works for any set of elements you're trying to target; the disadvantage is that not all properties can be easily reset.

Alternatively, if you're using jQuery, which does support :not(div > div) unlike the CSS version, you can place the selector in a script and, for instance, have jQuery apply a class name to those elements then target that class in your CSS.

2 of 2
4

It should work now thanks to Selectors Level 4 which allows :not() to take a list of complex selectors.

You can now also nest :not()... like :not(:not()) which wasn't allowed in Selectors Level 3. Not sure why you'd want to do that but you can.

🌐
Kau-Boys
kau-boys.com › home › nested css without preprocessors
Nested CSS without preprocessors - Kau-Boys
December 11, 2024 - That’s it! Just use nesting as in Sass, Less and other preprocessors and modern browsers will understand your code. If you still use a preprocessor for other things like variables, they will still convert this syntax into the normal “long CSS selectors”.
🌐
Emotion
emotion.sh › docs › nested
Emotion – Nested Selectors
Sometimes it's useful to nest selectors to target elements inside the current class or React component. An example with an element selector is shown below. import { css } from '@emotion/react' const paragraph = css` color: turquoise; a { border-bottom: 1px solid currentColor; cursor: pointer; } ` render( <p css={paragraph}> Some text.
🌐
web.dev
web.dev › articles › css nesting improves with cssnesteddeclarations
CSS nesting improves with CSSNestedDeclarations | Articles | web.dev
October 8, 2024 - When looking at the style property it's not clear that the background-color: green was declared after the nested CSSMediaRule. ↳ CSSStyleRule .type = STYLE_RULE .selectorText = ".foo" .style (CSSStyleDeclaration, 2) = - width: fit-content - background-color: green .cssRules (CSSRuleList, 1) = ↳ …
🌐
Savvy
savvy.co.il › blog › css & design › native css nesting: a complete guide with examples
Native CSS Nesting: A Complete Guide with Examples | Savvy
1 month ago - You can nest @media, @supports, @container, @layer, and other at-rules directly inside a selector block. This keeps responsive and conditional styles grouped with the component they belong to, improving readability and maintainability.
🌐
Delicious Reverie
deliciousreverie.co.uk › posts › selecting-parents-of-nested-element-css-has-selector
Selecting parents of a nested element with the css :has selector - Delicious Reverie
December 20, 2023 - But it makes sense if you think about it: by using :has() you’re scoping your CSS to the parent you’re using it on; anything appearing inside that pseudoselector works just like normal CSS does.