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 jackspace/claudeskillz tailwind-v4-shadcnreference/common-gotchas.mdpnpm add tailwindcss @tailwindcss/vite
pnpm add -D @types/node
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 base:root {
--brand: hsl(280 65% 60%);
--brand-foreground: hsl(0 0% 100%);
}
.dark {
--brand: hsl(280 75% 70%);
--brand-foreground: hsl(280 20% 10%);
}
@theme inline {
--color-brand: var(--brand);
--color-brand-foreground: var(--brand-foreground);
}<div className="bg-brand text-brand-foreground">Branded</div>reference/migration-guide.md<Button variant="destructive">Delete</Button> /* ✅ */
<Button className="bg-red-600">Delete</Button> /* ❌ */cn()import { cn } from "@/lib/utils"
<div className={cn(
"base-class",
isActive && "active-class",
hasError && "error-class"
)} /><Dialog>
<DialogTrigger asChild>
<Button>Open</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Title</DialogTitle>
</DialogHeader>
</DialogContent>
</Dialog>{
"dependencies": {
"tailwindcss": "^4.1.14",
"@tailwindcss/vite": "^4.1.14",
"clsx": "^2.1.1",
"tailwind-merge": "^3.3.1",
"@radix-ui/react-*": "latest",
"lucide-react": "^0.545.0",
"react": "^19.2.0",
"react-dom": "^19.2.0"
},
"devDependencies": {
"@types/node": "^24.0.0",
"@vitejs/plugin-react": "^5.0.4",
"vite": "^7.0.0",
"typescript": "~5.9.0"
}
}# These packages will cause build errors:
npm install tailwindcss-animate # ❌ Deprecated
npm install tw-animate-css # ❌ Doesn't exist@tailwindcss/motion@pluginpnpm add -D @tailwindcss/typography/* src/index.css */
@import "tailwindcss";
@plugin "@tailwindcss/typography";<article class="prose lg:prose-xl dark:prose-invert">
{{ markdown_content }}
</article>proseprose-smprose-baseprose-lgprose-xlprose-2xldark:prose-invertpnpm add -D @tailwindcss/forms/* src/index.css */
@import "tailwindcss";
@plugin "@tailwindcss/forms";// tailwind.config.js
module.exports = {
plugins: [require('@tailwindcss/typography')]
}@import "@tailwindcss/typography"; /* Doesn't work *//* src/index.css */
@import "tailwindcss";
@plugin "@tailwindcss/typography";
@plugin "@tailwindcss/forms";<div className="@container">
<div className="@md:text-lg">
Responds to container width, not viewport
</div>
</div>@tailwindcss/container-queriesreference/common-gotchas.mdcomponents.json"config": ""tailwind.config.ts