shadcn/ui not working with Tailwind v4: six causes and fixes
Unstyled or transparent shadcn components on Tailwind v4 come from v3 leftovers: the old PostCSS plugin, @tailwind directives, hsl() wrappers, missing imports.
- shadcn 4.23.0
- Tailwind CSS 4.3.5
- Vite 8
- React 19.3
When shadcn/ui components show up unstyled, transparent or half-styled on Tailwind CSS v4, the cause is nearly always a leftover from a v3 setup: an old PostCSS plugin, the old @tailwind directives, colours wrapped in hsl(), or a missing import. We broke a fresh shadcn 4.23 project on Tailwind 4.3.5 in each of these ways and wrote down what you see and how to fix it.
Start with the symptom that matches yours.
| What you see | Likely cause |
|---|---|
Build error about using tailwindcss as a PostCSS plugin | 1. The old PostCSS plugin |
| No Tailwind styles at all, no error | 2. v3 @tailwind directives |
| Buttons and cards have no background, text is fine | 3. hsl(var(--…)) around oklch values |
| Components from a package or another folder are unstyled | 4. Files Tailwind doesn't scan |
| Dialogs, sheets and accordions open without animation | 5. A missing import |
| Dark mode works on the page but not inside one section | 6. @theme without inline |
1. The old PostCSS plugin
A project upgraded from v3 often still has tailwindcss in postcss.config.js. v4 refuses it outright:
npm run buildIt looks like you're trying to use `tailwindcss` directly as a PostCSS plugin. The PostCSS plugin has moved to a separate package, so to continue using Tailwind CSS with PostCSS you'll need to install `@tailwindcss/postcss` and update your PostCSS configuration.On Vite (including Astro and React Router), drop PostCSS for Tailwind and use the Vite plugin. It's what shadcn init -t vite sets up:
import tailwindcss from "@tailwindcss/vite"import react from "@vitejs/plugin-react"import { defineConfig } from "vite" export default defineConfig({ plugins: [react(), tailwindcss()],})On Next.js or anything else that runs PostCSS, install @tailwindcss/postcss and use that instead. autoprefixer can go: v4 handles prefixes itself.
export default { plugins: { "@tailwindcss/postcss": {} },}2. v3 @tailwind directives
This one has no error. A stylesheet that starts with
@tailwind base;@tailwind components;@tailwind utilities;compiles on v4 to 65 bytes: the licence comment and nothing else. Replace the three lines with one:
@import "tailwindcss";3. hsl(var(--…)) around oklch values
shadcn/ui on v3 stored colours as bare HSL numbers (--primary: 222.2 47.4% 11.2%) and components wrapped them: hsl(var(--primary)). On v4 the CLI writes complete colours (--primary: oklch(0.205 0 0)) and uses them as they are.
Mix the two and the colour becomes invalid. We checked it in Chromium: hsl(var(--primary)) with an oklch value computes to rgba(0, 0, 0, 0), fully transparent. That's why buttons lose their fill while text stays readable.
Look for hsl(var( in your CSS and in any component you copied from an older project or tutorial, and remove the wrapper. In your theme, map the variables in @theme inline, not in a JavaScript config:
@theme inline { --color-primary: var(--primary); --color-primary-foreground: var(--primary-foreground);}If your whole theme is still in HSL numbers, the shadcn docs' v4 upgrade page converts them; or regenerate the theme with npx shadcn@latest init --force in a branch and copy the new variables over.
4. Files Tailwind doesn't scan
v4 detects your source files on its own, and skips anything in .gitignore. That includes node_modules. In a monorepo, components in packages/ui are outside the app folder and may not be scanned either. The classes in those files are never generated.
We confirmed it with a package in node_modules that uses bg-fuchsia-700: no class until we added a @source line, relative to the CSS file:
@import "tailwindcss";@source "../../../packages/ui/src";5. A missing import
A v4 shadcn project starts its CSS with four imports. Two of them are easy to lose in a merge or an upgrade:
@import "tailwindcss";@import "tw-animate-css";@import "shadcn/tailwind.css";tw-animate-css provides animate-in, fade-in-0 and the other animation classes. shadcn/tailwind.css comes from the shadcn package in your dependencies and defines the data-open: and data-closed: variants and the accordion keyframes. Remove it and the build still passes, but the variants match the wrong attribute. Details and the check are in shadcn animations not working.
6. @theme without inline
If you write the colour mapping as @theme { --color-primary: var(--primary); }, Tailwind puts --color-primary on :root and the utility reads that. A .dark class on a nested element changes --primary there, but --color-primary was already resolved on :root. In our test the nested element stayed white with plain @theme and turned black with @theme inline. Keep the inline keyword that shadcn writes.
A quick health check
The shadcn CLI can tell you what it thinks your project is:
npx shadcn@latest infoProject framework Vite (vite) tailwindVersion v4 tailwindConfig - tailwindCss src/index.css importAlias @tailwindVersion v4 with no tailwindConfig is what you want. The version comes from the Tailwind package you actually have installed. If tailwindConfig names a file, an old tailwind.config.js is still in the project. v4 ignores it unless your CSS loads it with @config, so anything you change in it has no effect. Move its values into your CSS and delete it.
Questions
Do I need a tailwind.config.js for shadcn/ui on Tailwind v4?
No. Leave "config": "" in the tailwind section of components.json. Everything lives in your CSS file. See does Tailwind 4 have a config file.
Is tailwindcss-animate still needed?
No. shadcn/ui replaced it with tw-animate-css in March 2025. If you still have tailwindcss-animate, swap it and import tw-animate-css in your CSS.
Can I remove the shadcn package from dependencies?
Not while your CSS imports shadcn/tailwind.css. The CLI itself you can run with npx, but that stylesheet is read from node_modules/shadcn. npx shadcn@latest eject inlines it if you want the package gone.
Related articles
- shadcn/uishadcn/ui animations not working on Tailwind v4Dialogs and accordions without animation mean a missing tw-animate-css or shadcn/tailwind.css import. Why the second one fails silently, and how to check.
- Tailwind CSS v4Does Tailwind CSS v4 have a config file?Not by default: v4 is configured in CSS with @theme. Where every v3 setting went, how to load an old tailwind.config.js with @config, and when to keep it.
- shadcn/uishadcn/ui dark mode not working? Check these seven thingsIs the dark class on <html>? If not: no provider, a flash on load, or Astro view transitions. If it is: colours without a dark value or @theme without inline.
Still stuck? We answer every message ourselves. Write to us