Tailwind v4 with Vite not working: plugin and CSS fixes
Fix Tailwind CSS v4 in Vite, React and Astro: register @tailwindcss/vite, remove leftover postcss.config.js, import tailwindcss, and configure @source.
- Tailwind CSS 4.3.5
- Vite 8
- Astro 7.4.13
If Tailwind CSS v4 utilities don't apply in a Vite project (React, Vue, Svelte or Astro), the cause is almost always one of four setup mismatches: the @tailwindcss/vite plugin is not registered in vite.config.ts, an old postcss.config.js is still running Tailwind v3, your CSS file isn't imported in main.tsx, or you still have @tailwind base directives.
The exact working Vite + Tailwind v4 setup
Step 1: Install tailwindcss and @tailwindcss/vite
npm install tailwindcss @tailwindcss/vitepnpm add tailwindcss @tailwindcss/viteyarn add tailwindcss @tailwindcss/vitebun add tailwindcss @tailwindcss/viteStep 2: Add the plugin to vite.config.ts
vite.config.tsTypeScript import { defineConfig } from "vite";import react from "@vitejs/plugin-react";import tailwindcss from "@tailwindcss/vite"; export default defineConfig({ plugins: [react(), tailwindcss()],});Step 3: Use @import "tailwindcss" in your entry stylesheet
src/index.cssCSS @import "tailwindcss";And make sure
src/main.tsximports it:import "./index.css";.
What to check when styles still don't show
- Leftover postcss.config.js: When you use
@tailwindcss/vite, you do not need PostCSS at all. Delete any oldpostcss.config.jsthat referencestailwindcssorautoprefixer— it will conflict with the Vite plugin. - Astro projects: Put
tailwindcss()insidevite: { plugins: [tailwindcss()] }inastro.config.mjs, and remove the deprecated@astrojs/tailwindintegration. - Monorepo / external packages: If components live in a sibling workspace package ignored by Git, add
@source "../../packages/ui/src";right after@import "tailwindcss";.
Questions
Should I use @tailwindcss/vite or @tailwindcss/postcss with Vite?
Always use @tailwindcss/vite. It hooks directly into Vite's module graph, runs faster during HMR, and avoids PostCSS config conflicts.
My Vite app works, but shadcn/ui components look unstyled
Check shadcn/ui not working with Tailwind v4 for the exact token and import checklist.
Related articles
- 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.
- Tailwind CSS v4Tailwind CSS v4 vs v3: what changed and how to upgradeCompare Tailwind CSS v4 and v3: @theme in CSS, OKLCH colours, renamed utilities, breaking defaults, and the exact upgrade steps with @tailwindcss/upgrade.
- shadcn/uishadcn/ui path aliases (@/) not working: tsconfig and Vite fixesFix Failed to resolve import "@/components/ui/..." in shadcn/ui: match tsconfig.json, tsconfig.app.json, vite.config.ts resolve.alias, and components.json.
Still stuck? We answer every message ourselves. Write to us