@csstools/postcss-nesting-experimental
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

PostCSS Nesting Experimental PostCSS

NPM Version CSS Standard Status Discord

PostCSS Nesting Experimental lets you nest style rules inside each other, following the CSS Nesting specification. If you want nested rules the same way Sass works you might want to use PostCSS Nested instead.

[!WARNING] Experimental version of PostCSS Nesting

a, b {
	color: red;

	& c, & d {
		color: white;
	}

	:is(e) & {
		color: yellow;
	}
}

& {
	color: pink;
}


/* becomes */

a, b {
	color: red;
}

:is(a,b) c, :is(a,b) d {
		color: white;
	}

:is(e) :is(a,b) {
		color: yellow;
	}

:scope {
	color: pink;
}

Relative selectors :

.parent {
	color: red;

	.child {
		color: white;
	}

	> .other-child {
		color: yellow;
	}
}

/* becomes */

.parent {
	color: red;
}

:is(.parent) .child {
	color: white;
}

:is(.parent)> .other-child {
	color: yellow;
}

Usage

Add PostCSS Nesting Experimental to your project:

npm install @csstools/postcss-nesting-experimental --save-dev

Use PostCSS Nesting Experimental as a PostCSS plugin:

import postcss from 'postcss';
import postcssNestingExperimental from '@csstools/postcss-nesting-experimental';

postcss([
  postcssNestingExperimental(/* pluginOptions */)
]).process(YOUR_CSS /*, processOptions */);

PostCSS Nesting Experimental runs in all Node environments, with special instructions for:

Node Webpack Gulp Grunt

⚠️ Spec disclaimer

The CSS Nesting specification states on nesting that "Declarations occurring after a nested rule are invalid and ignored.". While we think it makes sense on browsers, enforcing this at the plugin level introduces several constraints that would interfere with PostCSS' plugin nature such as with @mixin

Package Sidebar

Install

npm i @csstools/postcss-nesting-experimental

Weekly Downloads

7

Version

2.0.1

License

CC0-1.0

Unpacked Size

18.2 kB

Total Files

6

Last publish

Collaborators

  • romainmenke
  • alaguna
  • jonathantneal