Tailwind CSS v3 complains about nested rules in your stylesheet
Your error
Nested CSS was detected, but CSS nesting has not been configured correctly.3 more lines it can showFix it fast
Most common cause, 1 of 3No nesting plugin is listed ahead of tailwindcss
Put the bundled nesting plugin above tailwindcss.
// postcss.config.js
module.exports = {
plugins: {
'tailwindcss/nesting': {},
tailwindcss: {},
autoprefixer: {},
},
}Short answer
Tailwind CSS 3.0 to 3.4.1 warns "Nested CSS was detected, but CSS nesting has not been configured correctly"; 3.4.2 and later stay silent and fail only when @apply targets a class written with nesting. Both mean nested rules reached the tailwindcss PostCSS plugin unflattened. List tailwindcss/nesting before tailwindcss in postcss.config.js. Tailwind v4 flattens nesting on its own.
Which cause do you have?
Print the Tailwind version that is installed, then find the PostCSS config file the build should read and open it. The version tells you which of the two messages you have (the warning ends at 3.4.1), and the config shows whether anything flattens nesting before tailwindcss runs.
npm ls tailwindcss react-scripts
ls -a | grep -i postcssThen find the line you see in this list and open its fix:
- 1No nesting plugin is listed ahead of tailwindcss
postcss.config.js has tailwindcss in its plugins but no tailwindcss/nesting entry above it - 2postcss-preset-env is left to do the nesting
postcss-preset-env comes after tailwindcss in the plugin list and has no features: { 'nesting-rules': false } - 3Create React App ignores postcss.config.js
package.json scripts call react-scripts, and changes to postcss.config.js make no difference
What does the error look like?
Nested CSS was detected, but CSS nesting has not been configured correctly.Please enable a CSS nesting plugin *before* Tailwind in your configuration.The `card` class cannot be used with `@apply` because `@apply` does not currently support nested CSS.Rewrite the selector without nesting or configure the `tailwindcss/nesting` plugin:
Cause 1 of 3
No nesting plugin is listed ahead of tailwindcss
You seepostcss.config.js has tailwindcss in its plugins but no tailwindcss/nesting entry above it
Check
Tailwind v3 prints the nested CSS warning (up to 3.4.1) or rejects @apply of a nested class (3.4.2 on) when a rule written inside another rule gets to the tailwindcss plugin still nested. Version 3 leaves nesting to a separate plugin, tailwindcss/nesting, which ships inside the package, and its docs ask for that plugin to be listed before tailwindcss.
grep -n "nesting\|tailwindcss" postcss.config.*Fix
Put the bundled nesting plugin above tailwindcss. Left empty it uses postcss-nested, which reads Sass-style nesting; pass 'postcss-nesting' as its value when your CSS follows the native nesting syntax instead (install postcss-nesting first).
// postcss.config.js
module.exports = {
plugins: {
'tailwindcss/nesting': {},
tailwindcss: {},
autoprefixer: {},
},
}Verify
Run a fresh build and search its output for the message. No lines should come back, and the generated CSS should hold flat selectors such as .card:hover.
npm run build 2>&1 | grep -i "nested css"Confirmed by v3.tailwindcss.com
Cause 2 of 3
postcss-preset-env is left to do the nesting
You seepostcss-preset-env comes after tailwindcss in the plugin list and has no features: { 'nesting-rules': false }
Check
A project that counts on postcss-preset-env for nesting still sees the Tailwind nested CSS message when that preset is listed after tailwindcss, because it then flattens the rules only once Tailwind has already met them. Tailwind's v3 docs ask for its nesting feature to be off, with tailwindcss/nesting doing the job ahead of Tailwind.
grep -n -A3 "postcss-preset-env" postcss.config.*Fix
Switch off nesting-rules in the preset and hand nesting to tailwindcss/nesting. The docs' own example passes postcss-nesting, the spec-style engine, as its value.
// postcss.config.js
module.exports = {
plugins: {
'tailwindcss/nesting': 'postcss-nesting',
tailwindcss: {},
'postcss-preset-env': {
features: { 'nesting-rules': false },
},
},
}Verify
Rebuild, then open a page that uses the nested rule and confirm its hover or child styles apply.
npm run buildConfirmed by v3.tailwindcss.com
Cause 3 of 3
Create React App ignores postcss.config.js
You seepackage.json scripts call react-scripts, and changes to postcss.config.js make no difference
Check
In a Create React App project the nesting message survives any postcss.config.js change: react-scripts 5 passes config: false to postcss-loader and, as soon as tailwind.config.js exists, uses its own plugin list that starts with tailwindcss and holds no nesting plugin.
grep -n "react-scripts" package.json
ls tailwind.config.jsFix
Without ejecting there is no slot for the plugin, so write those selectors flat. Upgrading tailwindcss to 3.4.2 or later also ends the plain warning, leaving only @apply of a nested class as an error. The longer-term fix is to leave Create React App: the React team deprecated it in February 2025 and points existing apps to a framework or to Vite, Parcel or Rsbuild.
/* nested: needs a plugin under Tailwind v3 */
.card { padding: 1rem; &:hover { color: #b91c1c; } }
/* flat: works under react-scripts as it is */
.card { padding: 1rem; }
.card:hover { color: #b91c1c; }Verify
Start the dev server again; the compile output in the terminal shows no nesting message.
npm startConfirmed by github.com
How do I stop it coming back?
- Pin tailwindcss to 3.4.2 or newer in package.json so plain nested rules no longer raise the old warning, and keep tailwindcss/nesting for anything you @apply.
- Keep a single PostCSS config file in the repository, and recheck where tailwindcss sits in it each time a plugin is added.
- When you move to Tailwind v4, delete tailwindcss/nesting: v4 runs nested CSS through Lightning CSS and flattens it for you.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: TaxiDex, QistLock, Taskvare.