Tailwind CSSNext.jsError Fix2026 Updated

Tailwind CSS Classes Not Applying— Fixed [Complete Guide 2026]

Also covers: Tailwind v4 not working · styles not showing · classes purged in production

January 20266 min readTailwind v3 · v4 · Next.js

⚡ 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).

SymptomCauseFix
No styles at all — page unstyledglobals.css not importedJump →
Some classes work, some don'tContent paths incompleteJump →
Works in dev, broken in productionClasses purged — content paths wrongJump →
Dynamic classes missingConstructed strings not detectedJump →
v4 installed but nothing worksOld config format / importJump →
Tailwind classes lose to other CSSSpecificity conflictJump →
1

Tailwind v3 — Fix the Content Config

Classes being purged — most common cause
2 min

The content array tells Tailwind which files to scan for class names. If your files are not listed, their classes are purged.

tailwind.config.js
/** @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.

2

Tailwind v4 — New Setup for Next.js

Everything changed in v4 — old config does not work
5 min

Tailwind v4 (released early 2025) completely changed the configuration format. The old tailwind.config.js and @tailwind directives no longer work the same way.

terminal
npm install tailwindcss@latest @tailwindcss/postcss
postcss.config.mjs — v4 format
// ❌ OLD (v3)
export default {
  plugins: { tailwindcss: {}, autoprefixer: {} }
}

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

/* ✅ NEW (v4) — single import */
@import "tailwindcss";
app/layout.jsx
import './globals.css'  // ← must still be imported here

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <body>{children}</body>
    </html>
  )
}
3

CSS Not Imported in Root Layout

No Tailwind styles at all — completely unstyled
1 min

If your page has zero styles, globals.css is not imported in your root layout file.

app/layout.jsx
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>
  )
}
4

Dynamic Class Names Being Purged

Conditionally built class strings disappear
3 min

Tailwind scans your source for complete class name strings. If you build class names dynamically, Tailwind cannot detect them.

components/Button.jsx
// ❌ 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)/ },
  ]
}
5

PostCSS Not Configured

Tailwind plugin not running at all
2 min
postcss.config.js — v3
// Must exist in project root for Tailwind v3
module.exports = {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
  },
}
postcss.config.mjs — v4
export default {
  plugins: {
    '@tailwindcss/postcss': {},
  },
}
6

Specificity Conflict With Other CSS

Tailwind classes applied but overridden
2 min

If you import other CSS files or use CSS Modules alongside Tailwind, those styles may override Tailwind's utilities due to specificity.

Diagnosis
/* 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 */
7

Tailwind Dark Mode Not Working

Dark mode classes ignored
2 min
tailwind.config.js
module.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

Frequently Asked Questions

Why are Tailwind CSS classes not applying in Next.js?+
The most common causes: 1) The content array in tailwind.config.js does not include your file paths — Tailwind does not scan those files and purges the classes, 2) globals.css is not imported in your root layout, 3) Using Tailwind v4 without updating the config format.
Tailwind classes work in development but not in production?+
Your content paths in tailwind.config.js are wrong or too narrow. Tailwind only includes CSS classes it finds in the files listed in content. In development the full stylesheet is generated; in production it is purged. Fix the content array to include all your component files.
How do I use Tailwind v4 with Next.js?+
Tailwind v4 changed the configuration format significantly. Install @tailwindcss/postcss and update your postcss.config.js. The tailwind.config.js file is no longer needed for basic setup — configuration moves to your CSS file using @theme directive.
Why are dynamically constructed Tailwind classes not working?+
Tailwind scans your source files for complete class strings at build time. If you construct class names dynamically (e.g. 'text-' + color), Tailwind cannot detect them and removes them. Use complete class names or add them to the safelist in tailwind.config.js.
Tailwind CSS is not applying after upgrading to v4 — how to fix?+
Tailwind v4 changed how PostCSS is configured. Replace the plugins in postcss.config.js: use @tailwindcss/postcss instead of tailwindcss and autoprefixer. Also update your CSS import from @tailwind base/components/utilities to @import 'tailwindcss'.
How do I add classes to the Tailwind safelist?+
In tailwind.config.js: module.exports = { safelist: ['bg-red-500', 'text-blue-600', { pattern: /bg-(red|blue)-(100|500)/ }] }. This prevents those classes from being purged even if they are not found as complete strings in your source files.

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