Tailwind classes are in the code, but the styles do not show

Filed under Next.js & React errors

Most likely causeAbout 10 min · 6 steps

Tailwind never generated those classes, because your files are outside the config's content paths or the Tailwind directives are missing from your CSS.

Check content paths in tailwind.config.js
Confirm the @tailwind lines in your CSS
Restart the dev server

Fastest route

Give your AI this prompt

Copy it, replace the bracketed part with your error, and send it.

Preview the prompt
My Tailwind classes are in the markup but the styles do not show on the page — the elements render unstyled and there is no error.

Here is my setup: [paste the content array from tailwind.config.js, the top of your main CSS file, and say which folders your pages and components live in, e.g. src/app and src/components].

Please: 1) check whether every folder that uses classes is covered by the content patterns in tailwind.config.js, and fix the patterns if not, 2) check that my main CSS file contains the Tailwind directives (@tailwind base; @tailwind components; @tailwind utilities; — or @import "tailwindcss"; if I am on v4) and that my layout imports that CSS file, 3) search my code for class names built dynamically with template strings, which the scanner cannot see, and convert them to full class names.

Constraints: do not rewrite my components in plain CSS, do not change the visual design, make one change at a time, and tell me which cause you found before you change code.

Fix it yourself

Follow the repair

  1. Check the content paths in tailwind.config.js. Open the config and read the content array. Every folder holding files that use classes must be matched by one of these patterns:
    // tailwind.config.js
    module.exports = {
      content: [
        "./app/**/*.{js,ts,jsx,tsx}",
        "./components/**/*.{js,ts,jsx,tsx}",
        "./pages/**/*.{js,ts,jsx,tsx}",
      ],
      // ...
    };
    Now compare with where your files actually live. If the project keeps everything under src/, the patterns must start with ./src/ — a config generated for a root-level layout will scan politely past your entire app and find almost nothing.
  2. Confirm the Tailwind directives are in your CSS. Open your main CSS file — usually globals.css — and look for these three lines near the top:
    @tailwind base;
    @tailwind components;
    @tailwind utilities;
    Those lines are where the generated classes get injected; without them, perfect content paths still produce an empty result. Then confirm your root layout actually imports that CSS file. (On Tailwind v4 there is no config file by default — the equivalent is a single @import "tailwindcss"; line in the CSS, so check for that instead.)
  3. Restart the dev server after config changes. The config and content list are read when the server starts. Edit, save, restart — in that order. If a restart alone does not pick the styles up, stop the server, delete the framework's build cache (the .next folder in Next.js), and start again, so no stylesheet generated from the old config survives.
  4. Stop building class names dynamically. The scanner reads files as text; it never runs your code, so it cannot see a class that only exists at runtime:
    // Invisible to the scanner — never generated:
    className={`bg-${color}-500`}
    
    // Safe — complete class names the scanner can read:
    const colorClasses = { red: "bg-red-500", blue: "bg-blue-500" };
    className={colorClasses[color]}
    This is the cause to suspect when a component is unstyled only for some values — a status color, a size, a theme — while everything hard-coded around it works.
  5. If some classes work, you have your answer. Do not reinstall anything. Working classes prove Tailwind is installed, wired, and generating — the missing ones were simply never seen by the scanner. Test the theory in the failing file with a loud, unmistakable class like bg-red-500: if even that does not show, the file itself is outside the content paths; if it shows, the specific class you wanted is the problem — usually a dynamic name from step 4, or a typo.
  6. Check that PostCSS is still wired up. Save this for the case where literally no Tailwind class works anywhere, in any file. Most Next.js and Vite scaffolds run Tailwind through PostCSS, and if postcss.config.js was deleted or emptied during a cleanup, the Tailwind step never runs and the output CSS is just your hand-written styles. Restore the scaffold's original version of that file instead of hand-editing around it.
Why this happensOptional explanation

Tailwind works differently from a normal CSS library. There is no giant stylesheet with every class waiting in your project. At build time, Tailwind scans a list of files — the content paths in your config — reads every class name it finds there as plain text, and generates a small stylesheet containing only those. Your markup can ask for any class it likes, but if that class was never generated, the browser has nothing to apply, and the element renders unstyled with no error anywhere to point at.

That design keeps production CSS tiny, but it makes the config load-bearing. Move your components into a folder the patterns do not cover, scaffold the project under src/ while the patterns point at the root, or delete the @tailwind lines from the CSS file while tidying up — each one quietly disconnects the generator from your code. The page still renders and the classes still sit in your markup looking perfectly correct, which is why this failure is so confusing the first time it happens.

  • Content paths do not cover your files: folders like src/, a components folder, or a renamed app directory missing from the content array — the number one cause.
  • Missing CSS directives: the @tailwind lines (or v4's import) are gone from the CSS file, so nothing gets generated even with perfect paths.
  • Dynamically built class names: template strings that assemble classes at runtime are invisible to a scanner that only reads text.
  • Stale dev server or cache: the config is already fixed, but the running server still serves the stylesheet generated from the old one.

Quick answers

Some styles work and others don't. Is Tailwind half installed?

No — that split is the scanner's fingerprint. Classes in files covered by the content paths got generated; classes anywhere else were never seen. Fix the paths (or a dynamically built class name) and the missing styles appear after a restart.

I use Tailwind v4 and there is no tailwind.config.js. What do I check?

Version 4 configures itself in CSS: look for @import "tailwindcss" in your main CSS file and confirm your layout loads that file. Content detection is automatic in v4, but folders outside the project root, or ignored by git, may need an explicit @source line.

Why did it break when I moved my components into a new folder?

Because the content patterns in tailwind.config.js still point at the old locations. Tailwind kept scanning the old folders faithfully — it just found fewer and fewer classes there. Add the new folder to the content array and restart.

One fix, every Friday.

One real error, explained in plain English, with the fix — in your inbox every Friday. No spam, no jargon, unsubscribe anytime.