Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

Tailwind classes have no effect in a Next.js app

ErrorTailwind classes are in the markup but nothing is styled

Short answer

The page loads but Tailwind classes do nothing when the generated CSS never reaches the page. Usual reasons: globals.css is not imported in the root layout, v3 directives are used with v4 installed (or the reverse), the PostCSS plugin is wrong for the version, or v3 content paths miss your folders.

  • Applies to Next.js 15, Next.js 16, Tailwind CSS 3.4, Tailwind CSS 4
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find out which major version you have installed, because v3 and v4 are set up differently.

    npm ls tailwindcss @tailwindcss/postcss
    cat postcss.config.* app/globals.css | head -20
  2. 2Match what you see, then jump to its fix

    1. 1No Tailwind styles at all, even for simple classesglobals.css is not imported in the root layoutFix
    2. 2The CSS file starts with @tailwind base; and tailwindcss is version 4v3 directives with Tailwind v4 installedFix
    3. 3Tailwind v4 with plugins: { tailwindcss: {} } in postcss.configThe PostCSS plugin is wrong for the installed versionFix
    4. 4Tailwind v3; classes in some folders work and in others do notv3 content paths do not cover your foldersFix
    5. 5Custom theme values from tailwind.config.js do not apply in v4tailwind.config.js is ignored in v4Fix

What does the error look like?

  • Tailwind classes are in the markup but nothing is styled
  • Styles from Tailwind never reach the page after install

Cause 1 of 5

globals.css is not imported in the root layout

1Check

The stylesheet that holds the Tailwind import must be imported by the root layout.

grep -n "globals.css" app/layout.*

2Fix

Import it at the top of the root layout.

// app/layout.tsx
import './globals.css'

3Verify

Reload; a class like text-3xl now changes the page.

npm run dev

Confirmed by nextjs.org

Did this fix it?

Cause 2 of 5

v3 directives with Tailwind v4 installed

1Check

In v4 you import Tailwind with a normal CSS @import, not the @tailwind directives.

head -5 app/globals.css

2Fix

Replace the three directives with one import.

/* app/globals.css */
@import "tailwindcss";

3Verify

Restart the dev server and check a utility class.

npm run dev

Confirmed by tailwindcss.com

Did this fix it?

Cause 3 of 5

The PostCSS plugin is wrong for the installed version

1Check

In v3 the tailwindcss package is the PostCSS plugin. In v4 the plugin lives in @tailwindcss/postcss.

cat postcss.config.*

2Fix

For v4, install the plugin and use it.

npm install tailwindcss @tailwindcss/postcss postcss

// postcss.config.mjs
const config = {
  plugins: {
    "@tailwindcss/postcss": {},
  },
};
export default config;

3Verify

Restart the dev server.

npm run dev

Confirmed by tailwindcss.com

Did this fix it?

Cause 4 of 5

v3 content paths do not cover your folders

1Check

The content array in tailwind.config.js lists where Tailwind looks for class names.

cat tailwind.config.js

2Fix

Add every folder that holds components.

module.exports = {
  content: [
    './app/**/*.{js,ts,jsx,tsx,mdx}',
    './pages/**/*.{js,ts,jsx,tsx,mdx}',
    './components/**/*.{js,ts,jsx,tsx,mdx}',
  ],
  theme: { extend: {} },
  plugins: [],
}

3Verify

Restart the dev server and recheck the missing class.

npm run dev

Confirmed by nextjs.org

Did this fix it?

Cause 5 of 5

tailwind.config.js is ignored in v4

1Check

v4 no longer detects JavaScript config files automatically.

ls tailwind.config.*

2Fix

Load it from your CSS file with @config, or move the settings into CSS.

/* app/globals.css */
@import "tailwindcss";
@config "../tailwind.config.js";

3Verify

Restart and check a custom theme class.

npm run dev

Confirmed by tailwindcss.com

Did this fix it?

How do I stop it coming back?

  • Follow one setup guide for the exact major version you install.
  • Restart the dev server after editing PostCSS or Tailwind config.
  • Pin the Tailwind major version in package.json.

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 built on the same technologies:

Related fixes

Web apps

Next.js fails with Cannot find module 'tailwindcss'

Error: Cannot find module 'tailwindcss'

Next.js loads Tailwind through PostCSS, so the error means the package named in postcss.config is not installed where the build runs.

3 causes, each with a fix

Web apps

A custom Tailwind color does not apply to the element

text-primary works in one component but not in another

Tailwind only creates a color class when it finds the whole class name in your source, and in v4 only when the color is defined in the --color-* theme namespace.

4 causes, each with a fix

Web apps

Hydration failed after adding next-themes dark mode

Console reports a server and client mismatch on the html element

next-themes changes the html element and knows the theme only in the browser, so server HTML and client HTML differ.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.