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
| Symptom | Cause | Fix |
|---|---|---|
| Page is completely unstyled | globals.css not imported | Jump → |
| Some classes work, some don't | content paths incomplete | Jump → |
| Works locally, broken in production | classes purged — wrong content paths | Jump → |
| v4 installed — nothing works | old PostCSS config / CSS import | Jump → |
| Dynamic colors missing | constructed strings not detected | Jump → |
| Tailwind and CSS Modules fighting | specificity conflict | Jump → |
11 min
Import globals.css in Root Layout
Page completely unstyled — zero Tailwind classes appliedapp/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.
22 min
Tailwind v3 Content Config for App Router
Classes purged — content paths wrongtailwind.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}']35 min
Tailwind v4 Setup for Next.js
Everything changed — old config format does not workterminal
npm install tailwindcss@latest @tailwindcss/postcsspostcss.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.
42 min
Dynamic Class Names Being Purged
Conditional colors or sizes not applyingcomponents/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: [...]
}51 min
Restart Dev Server After Config Changes
Most overlooked stepterminal
# 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 completely62 min
Tailwind With CSS Modules Conflict
Tailwind classes overridden by module CSScomponents/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 automaticallyTailwind v4 + Next.js App Router (manual)
terminal
npm install next react react-dom
npm install -D tailwindcss@latest @tailwindcss/postcsspostcss.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
- Always import globals.css as the first import in app/layout.jsx
- Include all file extensions in content: {js,ts,jsx,tsx,mdx}
- Restart dev server after any change to tailwind.config.js or postcss.config.js
- Never construct Tailwind class names dynamically — use complete string maps
- After upgrading to v4 — update PostCSS config and CSS import immediately
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