Tailwind CSSNext.jsError Fix2026 Updated

Tailwind CSS Not Working With Next.js App Router— Fixed [2026]

Also covers: Tailwind v4 setup · classes purged in production · dynamic classes missing

January 20266 min readTailwind v3 · v4 · Next.js 13–15

⚡ Check These Three Things First

1. globals.css imported in app/layout.jsx?

2. tailwind.config.js content includes ./app/**/*.{js,ts,jsx,tsx,mdx}?

3. Dev server restarted after config changes?

Diagnose Your Tailwind Issue

SymptomCauseFix
Page is completely unstyledglobals.css not importedJump →
Some classes work, some don'tcontent paths incompleteJump →
Works locally, broken in productionclasses purged — wrong content pathsJump →
v4 installed — nothing worksold PostCSS config / CSS importJump →
Dynamic colors missingconstructed strings not detectedJump →
Tailwind and CSS Modules fightingspecificity conflictJump →
1

Import globals.css in Root Layout

Page completely unstyled — zero Tailwind classes applied
1 min
app/layout.jsx
import './globals.css'   // ← THIS LINE IS REQUIRED — must be first

export const metadata = { title: 'My App' }

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <body className="bg-white text-gray-900 antialiased">
        {children}
      </body>
    </html>
  )
}

globals.css must be imported in the root layout — app/layout.jsx — not in individual page files. Importing it in page.jsx works for that page only.

2

Tailwind v3 Content Config for App Router

Classes purged — content paths wrong
2 min
tailwind.config.js
/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [
    './app/**/*.{js,ts,jsx,tsx,mdx}',        // App Router — required
    './pages/**/*.{js,ts,jsx,tsx,mdx}',      // Pages Router (if mixed)
    './components/**/*.{js,ts,jsx,tsx,mdx}', // components folder
    './src/**/*.{js,ts,jsx,tsx,mdx}',        // src/ directory (if used)
  ],
  theme: { extend: {} },
  plugins: [],
}

// ❌ Too narrow — misses .js and .jsx files
content: ['./app/**/*.tsx']

// ❌ Missing the app/ folder entirely
content: ['./components/**/*.{js,ts,jsx,tsx}']
3

Tailwind v4 Setup for Next.js

Everything changed — old config format does not work
5 min
terminal
npm install tailwindcss@latest @tailwindcss/postcss
postcss.config.mjs — v4 format
// ❌ v3 (old)
export default { plugins: { tailwindcss: {}, autoprefixer: {} } }

// ✅ v4 (new)
export default { plugins: { '@tailwindcss/postcss': {} } }
app/globals.css — v4 import
/* ❌ v3 (old) */
@tailwind base;
@tailwind components;
@tailwind utilities;

/* ✅ v4 (new) — single line replaces all three */
@import "tailwindcss";

After switching to v4, delete tailwind.config.js if it is empty — v4 no longer needs it for basic setup. Content detection is automatic in v4.

4

Dynamic Class Names Being Purged

Conditional colors or sizes not applying
2 min
components/Badge.jsx
// ❌ WRONG — Tailwind cannot detect 'bg-red-500' in this string
const color = 'red'
<div className={`bg-${color}-500`}>

// ✅ CORRECT — full class names as complete strings
const colorMap = {
  red:    'bg-red-500 text-red-900',
  green:  'bg-green-500 text-green-900',
  blue:   'bg-blue-500 text-blue-900',
}
<div className={colorMap[color]}>

// ✅ OR add to safelist in tailwind.config.js
module.exports = {
  safelist: [
    'bg-red-500', 'bg-green-500', 'bg-blue-500',
    { pattern: /bg-(red|green|blue)-(100|500|900)/ },
  ],
  content: [...]
}
5

Restart Dev Server After Config Changes

Most overlooked step
1 min
terminal
# Next.js does NOT hot-reload tailwind.config.js or postcss.config.js
# After ANY change to these files:
Ctrl+C           # stop the server
npm run dev      # restart completely
6

Tailwind With CSS Modules Conflict

Tailwind classes overridden by module CSS
2 min
components/Button.jsx
// ❌ CSS Modules can override Tailwind
import styles from './Button.module.css'
<button className={`${styles.btn} bg-indigo-600`}>

// ✅ Use !important modifier to force Tailwind to win
<button className={`${styles.btn} !bg-indigo-600`}>

// ✅ Better — choose one system per component, don't mix
// Option A: pure Tailwind
<button className="bg-indigo-600 text-white px-4 py-2 rounded-lg">

// Option B: pure CSS Modules (import + className={styles.btn})

Fresh Working Setup

Tailwind v3 + Next.js App Router

terminal
npx create-next-app@latest my-app --tailwind
# This sets up Tailwind v3 with the correct config automatically

Tailwind v4 + Next.js App Router (manual)

terminal
npm install next react react-dom
npm install -D tailwindcss@latest @tailwindcss/postcss
postcss.config.mjs
export default { plugins: { '@tailwindcss/postcss': {} } }
app/globals.css
@import 'tailwindcss';
app/layout.jsx
import './globals.css'
export default function RootLayout({ children }) {
  return <html lang="en"><body>{children}</body></html>
}

Prevention

Frequently Asked Questions

Why is Tailwind CSS not working in Next.js App Router?+
The three most common causes: 1) globals.css is not imported in app/layout.jsx, 2) The content array in tailwind.config.js does not include app/**/*.{js,ts,jsx,tsx} paths, 3) Using Tailwind v4 with old v3 PostCSS config. Check each in order.
Tailwind works in Pages Router but not App Router — why?+
The content paths changed. App Router uses the app/ directory instead of pages/. Update your tailwind.config.js content array: './app/**/*.{js,ts,jsx,tsx,mdx}'. Also verify globals.css is imported in app/layout.jsx not pages/_app.jsx.
Tailwind works locally but classes are missing in production?+
Your content paths in tailwind.config.js are too narrow and classes are being purged. Make sure you include all file extensions: './app/**/*.{js,ts,jsx,tsx,mdx}'. Restart dev server and run a fresh production build to verify.
How do I set up Tailwind v4 with Next.js?+
npm install tailwindcss@latest @tailwindcss/postcss. Update postcss.config.mjs to use '@tailwindcss/postcss': {}. In globals.css replace the three @tailwind directives with a single @import 'tailwindcss'. Restart the dev server.
Tailwind IntelliSense not working in Next.js — how to fix?+
Install the Tailwind CSS IntelliSense VS Code extension. Make sure tailwind.config.js exists in project root. If using v4, add a tailwind.config.js with just module.exports = {} to help the extension detect the project.
Some Tailwind classes work and others don't — why?+
Missing classes are being purged because they only exist as dynamically constructed strings. For example: 'text-' + color will not be detected. Always use complete class names as static strings and add dynamic ones to the safelist in tailwind.config.js.

Need Expert Help?

We Build Production Next.js Apps With Tailwind

Softplix builds full-stack Next.js applications. Need help with Tailwind setup or CSS architecture? We can help.

Talk to an Engineer