Skip to content
>_VibeUnstuck

Tailwind class not applying

Last verified:

The fix

Tailwind class not applying: that utility was never generated. Tailwind only ships complete class names written in source. Do not concatenate the name.

  1. 1

    Write the full class name

    Replace concatenated names with a map of complete strings. The scanner has to see bg-red-500 in the file.

    const backgrounds = {
      red: "bg-red-500",
      green: "bg-green-500",
    } as const;
    
    export function Swatch({ tone }: { tone: keyof typeof backgrounds }) {
      return <div className={backgrounds[tone]} />;
    }
  2. 2

    Confirm the pipeline that is actually running

    v4: the global CSS starts with @import "tailwindcss". v3: content includes the directory of the component, for example ./app/**/*.{ts,tsx} and ./components/**/*.{ts,tsx}. Do not load Tailwind from a CDN script and from the PostCSS build at the same time.

  3. 3

    Cover extra folders

    If components live outside the app root that Tailwind watches, add them. In v4 that is an @source directive. In v3 it is another content glob. Restart the dev server after config edits.

  4. 4

    Check you are looking at the latest CSS

    A stale production build, or a browser cache of an old CSS file, shows classes that the new source no longer matches. Hard-refresh. On Vercel, inspect the CSS from the deployment you just built, not an older alias.

Why it happens

Tailwind scans source files for complete class names. It does not execute your JavaScript. A class built at runtime, such as ` bg-${color}-500 `, is invisible to the scanner, so the CSS rule is never generated. The element has the class attribute and no style.

In Tailwind v3 the scan list is the content array. A new folder that is not listed is unscanned. In v4 the CSS entry has to @import "tailwindcss", and files outside the default sources need @source. A second, plain CSS file that the app actually loads will not contain the utilities.

The next error you'll probably hit

Once this is fixed, the usual follow-up is Can't resolve '@/components/ui/button'. Can't resolve '@/components/ui/button': the v0 snippet expects shadcn files you do not have. Add those files or drop the import. In Vite, remove next/link.

Prompt to paste back into your AI tool

Paste this above the error.

Tailwind classes are present in the className string and have no effect.

Do not add a <script> CDN for Tailwind on top of the existing build. Do not turn on every plugin.

1. If the class name is built with string concatenation, replace it with a map of complete class strings.
2. If the file is outside the scanned folders, add the folder (content in v3, @source in v4).
3. Confirm the CSS entry imports Tailwind once.
4. Tell me to restart the dev server. Do not restyle unrelated components.

Common questions

+Why does bg-red-500 work when I type it, but not when it comes from a variable?

The scanner never sees the finished string if you assemble it with a template. It only sees the pieces. Put the full class in the source.

+The class works in dev and not in the production build. Why?

Dev can be more forgiving about which files it watches. The production scan uses the configured sources. Add the folder, and make sure you are not also purging a class that only appears in a string.

Related errors