Tailwind CSS Classes Not Applying— Fixed [Complete Guide 2026]
Also covers: Tailwind v4 not working · styles not showing · classes purged in production
⚡ Identify Your Version First
Tailwind v3
Fix content array in tailwind.config.js → Fix 1
Tailwind v4
New PostCSS config and CSS import → Fix 2
Why Tailwind Classes Are Not Applying
Tailwind is a utility-first CSS framework that only includes the CSS for classes it finds in your source files. If a class is not found during the build scan, it is not included in the output CSS — and therefore has no effect. This process is called purging (v3) or content detection (v4).
| Symptom | Cause | Fix |
|---|---|---|
| No styles at all — page unstyled | globals.css not imported | Jump → |
| Some classes work, some don't | Content paths incomplete | Jump → |
| Works in dev, broken in production | Classes purged — content paths wrong | Jump → |
| Dynamic classes missing | Constructed strings not detected | Jump → |
| v4 installed but nothing works | Old config format / import | Jump → |
| Tailwind classes lose to other CSS | Specificity conflict | Jump → |
Tailwind v3 — Fix the Content Config
Classes being purged — most common causeThe content array tells Tailwind which files to scan for class names. If your files are not listed, their classes are purged.
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
'./app/**/*.{js,ts,jsx,tsx,mdx}', // App Router
'./pages/**/*.{js,ts,jsx,tsx,mdx}', // Pages Router
'./components/**/*.{js,ts,jsx,tsx,mdx}',
'./src/**/*.{js,ts,jsx,tsx,mdx}', // if using src/ directory
],
theme: { extend: {} },
plugins: [],
}
// ❌ Common mistake — too narrow
content: ['./app/**/*.tsx'] // misses .js, .jsx files
// ❌ Another common mistake — missing directories
content: ['./components/**/*.{js,ts,jsx,tsx}'] // misses app/ pages/After changing tailwind.config.js, always restart your dev server — Next.js does not hot reload config changes.
Tailwind v4 — New Setup for Next.js
Everything changed in v4 — old config does not workTailwind v4 (released early 2025) completely changed the configuration format. The old tailwind.config.js and @tailwind directives no longer work the same way.
npm install tailwindcss@latest @tailwindcss/postcss// ❌ OLD (v3)
export default {
plugins: { tailwindcss: {}, autoprefixer: {} }
}
// ✅ NEW (v4)
export default {
plugins: { '@tailwindcss/postcss': {} }
}/* ❌ OLD (v3) */
@tailwind base;
@tailwind components;
@tailwind utilities;
/* ✅ NEW (v4) — single import */
@import "tailwindcss";import './globals.css' // ← must still be imported here
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}CSS Not Imported in Root Layout
No Tailwind styles at all — completely unstyledIf your page has zero styles, globals.css is not imported in your root layout file.
import './globals.css' // ← THIS LINE IS REQUIRED
export const metadata = { title: 'My App' }
export default function RootLayout({ children }) {
return (
<html lang="en">
<body className="bg-white text-gray-900">
{children}
</body>
</html>
)
}Dynamic Class Names Being Purged
Conditionally built class strings disappearTailwind scans your source for complete class name strings. If you build class names dynamically, Tailwind cannot detect them.
// ❌ WRONG — Tailwind cannot detect these
const color = 'red'
return <div className={`bg-${color}-500`}> // 'bg-red-500' not in source as string
// ❌ Also wrong
const classes = { danger: 'bg-red', success: 'bg-green' }
return <div className={`${classes[type]}-500`}>
// ✅ CORRECT — full class names as complete strings
const colorMap = {
danger: 'bg-red-500 hover:bg-red-600',
success: 'bg-green-500 hover:bg-green-600',
info: 'bg-blue-500 hover:bg-blue-600',
}
return <div className={colorMap[type]}>
// ✅ ALSO CORRECT — add to safelist for truly dynamic cases
// tailwind.config.js
module.exports = {
safelist: [
'bg-red-500', 'bg-green-500', 'bg-blue-500',
{ pattern: /bg-(red|green|blue)-(100|500|900)/ },
]
}PostCSS Not Configured
Tailwind plugin not running at all// Must exist in project root for Tailwind v3
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}export default {
plugins: {
'@tailwindcss/postcss': {},
},
}Specificity Conflict With Other CSS
Tailwind classes applied but overriddenIf you import other CSS files or use CSS Modules alongside Tailwind, those styles may override Tailwind's utilities due to specificity.
/* Check browser DevTools — if Tailwind class appears with strikethrough,
another rule is overriding it */
/* Option 1 — use !important modifier */
<div className="!text-red-500"> {/* ← forces Tailwind to win */}
/* Option 2 — remove conflicting global CSS */
/* Option 3 — import order matters */
/* In globals.css, import Tailwind LAST */
@import './other-styles.css';
@import 'tailwindcss'; /* v4 */Tailwind Dark Mode Not Working
Dark mode classes ignoredmodule.exports = {
darkMode: 'class', // ← 'class' uses .dark class on <html>
// or
darkMode: 'media', // ← 'media' uses prefers-color-scheme
content: [...],
}
// For 'class' mode — add/remove 'dark' class on <html>
// app/layout.jsx
<html lang="en" className="dark"> {/* force dark */}
// For dynamic toggle:
document.documentElement.classList.toggle('dark')Prevention
- Always include all file extensions in content: ['./app/**/*.{js,ts,jsx,tsx,mdx}']
- Restart dev server after any change to tailwind.config.js
- Never construct Tailwind class names dynamically — always use complete strings
- Add dynamic classes to the safelist in tailwind.config.js
- After upgrading to v4: update postcss.config and CSS import immediately
- Verify globals.css is imported at the top of your root layout
Frequently Asked Questions
Why are Tailwind CSS classes not applying in Next.js?+−
Tailwind classes work in development but not in production?+−
How do I use Tailwind v4 with Next.js?+−
Why are dynamically constructed Tailwind classes not working?+−
Tailwind CSS is not applying after upgrading to v4 — how to fix?+−
How do I add classes to the Tailwind safelist?+−
Need Expert Help?
We Build Production-Grade Next.js Apps
Softplix builds full-stack Next.js applications with Tailwind CSS. Need help with your project setup or Tailwind configuration? We can help.
Talk to an Engineer