Loading...
Loading...
Production-tested setup for Tailwind CSS v4 with shadcn/ui, Vite, and React. Use when: initializing React projects with Tailwind v4, setting up shadcn/ui, implementing dark mode, debugging CSS variable issues, fixing theme switching, migrating from Tailwind v3, or encountering color/theming problems. Covers: @theme inline pattern, CSS variable architecture, dark mode with ThemeProvider, component composition, vite.config setup, common v4 gotchas, and production-tested patterns. Keywords: Tailwind v4, shadcn/ui, @tailwindcss/vite, @theme inline, dark mode, CSS variables, hsl() wrapper, components.json, React theming, theme switching, colors not working, variables broken, theme not applying, @plugin directive, typography plugin, forms plugin, prose class, @tailwindcss/typography, @tailwindcss/forms
npx skill4agent add secondsky/claude-skills tailwind-v4-shadcnreference/common-gotchas.mdbun add tailwindcss @tailwindcss/vite
# or: npm install tailwindcss @tailwindcss/vite
bun add -d @types/node
# Note: Using pnpm for shadcn init due to known Bun compatibility issues
# (bunx has "Script not found" and postinstall/msw problems)
pnpm dlx shadcn@latest init// vite.config.ts
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'
import path from 'path'
export default defineConfig({
plugins: [react(), tailwindcss()],
resolve: {
alias: {
'@': path.resolve(__dirname, './src')
}
}
}){
"tailwind": {
"config": "", // ← CRITICAL: Empty for v4
"css": "src/index.css",
"cssVariables": true
}
}rm tailwind.config.ts # v4 doesn't use this file/* src/index.css */
@import "tailwindcss";
:root {
--background: hsl(0 0% 100%); /* ← hsl() wrapper required */
--foreground: hsl(222.2 84% 4.9%);
--primary: hsl(221.2 83.2% 53.3%);
/* ... all light mode colors */
}
.dark {
--background: hsl(222.2 84% 4.9%);
--foreground: hsl(210 40% 98%);
--primary: hsl(217.2 91.2% 59.8%);
/* ... all dark mode colors */
}@layer basehsl().dark.dark { @theme { } }@theme inline {
--color-background: var(--background);
--color-foreground: var(--foreground);
--color-primary: var(--primary);
/* ... map ALL CSS variables */
}bg-backgroundtext-primarybg-primary@layer base {
body {
background-color: var(--background); /* NO hsl() here */
color: var(--foreground);
}
}var(--background)hsl(var(--background))<div className="bg-background text-foreground">
{/* No dark: variants needed - theme switches automatically */}
</div>reference/dark-mode.md// Copy from: templates/theme-provider.tsx// src/main.tsx
import { ThemeProvider } from '@/components/theme-provider'
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<ThemeProvider defaultTheme="dark" storageKey="vite-ui-theme">
<App />
</ThemeProvider>
</React.StrictMode>,
)pnpm dlx shadcn@latest add dropdown-menureference/dark-mode.mdhsl():root.dark--background: hsl(0 0% 100%); /* ✅ Correct */@theme inline@theme inline {
--color-background: var(--background);
}"tailwind.config": ""{ "tailwind": { "config": "" } }tailwind.config.ts@tailwindcss/vitecn()import { cn } from "@/lib/utils"
<div className={cn("base", isActive && "active")} />:root.dark@layer base/* WRONG */
@layer base {
:root { --background: hsl(...); }
}.dark { @theme { } }/* WRONG - v4 doesn't support nested @theme */
.dark {
@theme {
--color-primary: hsl(...);
}
}/* WRONG */
body {
background-color: hsl(var(--background));
}tailwind.config.ts/* WRONG - v4 ignores this */
export default {
theme: {
extend: {
colors: { primary: 'hsl(var(--primary))' }
}
}
}@applydark:/* WRONG */
<div className="bg-primary dark:bg-primary-dark" />
/* CORRECT */
<div className="bg-primary" />:root {
--destructive: hsl(0 84.2% 60.2%); /* Red - errors, critical */
--success: hsl(142.1 76.2% 36.3%); /* Green - success states */
--warning: hsl(38 92% 50%); /* Yellow - warnings */
--info: hsl(221.2 83.2% 53.3%); /* Blue - info, primary */
}<div className="bg-destructive text-destructive-foreground">Critical</div>
<div className="bg-success text-success-foreground">Success</div>
<div className="bg-warning text-warning-foreground">Warning</div>
<div className="bg-info text-info-foreground">Info</div>| Symptom | Cause | Fix |
|---|---|---|
| Missing | Add |
| Colors all black/white | Double | Use |
| Dark mode not switching | Missing ThemeProvider | Wrap app in |
| Build fails | | Delete the file |
| Text invisible | Wrong contrast colors | Check color definitions in |
reference/common-gotchas.mdtemplates/cn()@tailwindcss/vitevite.config.tstailwindcss()tsconfig.jsoncomponents.json"config": ""tailwind.config.tssrc/index.css:root.darkhsl()@theme inline@layer basereferences/advanced-usage.mdreferences/migration-guide.md:root { --brand: hsl(280 65% 60%); }
@theme inline { --color-brand: var(--brand); }<div className="bg-brand">Branded</div>references/advanced-usage.md{
"dependencies": {
"tailwindcss": "^4.1.17",
"@tailwindcss/vite": "^4.1.17",
"clsx": "^2.1.1",
"tailwind-merge": "^3.3.1",
"@radix-ui/react-*": "latest",
"lucide-react": "^0.554.0",
"react": "^19.2.0",
"react-dom": "^19.2.0"
},
"devDependencies": {
"@types/node": "^24.10.1",
"@vitejs/plugin-react": "^5.1.1",
"vite": "^7.2.4",
"typescript": "~5.9.3"
}
}# These packages will cause build errors:
bun add tailwindcss-animate # ❌ Deprecated
# or: npm install tailwindcss-animate # ❌ Deprecated
bun add tw-animate-css # ❌ Doesn't exist@tailwindcss/motion@plugin@import "tailwindcss";
@plugin "@tailwindcss/typography";
@plugin "@tailwindcss/forms";@import "@tailwindcss/typography"@plugin "@tailwindcss/typography"@tailwindcss/container-queriesreferences/plugins-reference.mdreferences/common-gotchas.mdreferences/dark-mode.mdreferences/migration-guide.mdreferences/plugins-reference.mdreferences/advanced-usage.mdreference/common-gotchas.mdcomponents.json"config": ""tailwind.config.ts