I ran the old npx tailwindcss init -p from the v3 docs and it fails on v4. What is the correct setup for Vite and for Next.js?
#tailwind#tailwind-4#vite#postcss
DEV3 Developer Forum
Every post is reviewed first. Usually reviewed within 24 hours.
I ran the old npx tailwindcss init -p from the v3 docs and it fails on v4. What is the correct setup for Vite and for Next.js?
#tailwind#tailwind-4#vite#postcss
Tailwind 4 changes
There is no required tailwind.config.js, no content array (files are detected automatically) and no @tailwind base/components/utilities directives. You import Tailwind from CSS.
Vite (recommended path)
npm install tailwindcss @tailwindcss/vite
vite.config.ts:
import { defineConfig } from 'vite'
import tailwindcss from '@tailwindcss/vite'
export default defineConfig({
plugins: [tailwindcss()],
})
src/index.css:
@import "tailwindcss";
Import that CSS file in your entry (main.ts), then use classes in your templates.
Next.js and other PostCSS setups
npm install tailwindcss @tailwindcss/postcss postcss
postcss.config.mjs:
export default {
plugins: {
"@tailwindcss/postcss": {},
},
}
Then in app/globals.css: @import "tailwindcss";. Remove autoprefixer and postcss-import, v4 handles vendor prefixes and imports itself.
Customising in CSS
@import "tailwindcss";
@theme {
--font-sans: "Inter", ui-sans-serif, system-ui, sans-serif;
--color-brand-500: oklch(0.62 0.19 260);
}
If you must keep a JS config
Load it explicitly: @config "../../tailwind.config.js"; (it is not auto-detected anymore).
Pitfalls