Skip to content

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.

Updated 3 December 2026Tested with
  • 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

  1. Step 1: Install tailwindcss and @tailwindcss/vite

    npm install tailwindcss @tailwindcss/vite
  2. Step 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()],});
  3. Step 3: Use @import "tailwindcss" in your entry stylesheet

    src/index.cssCSS
    @import "tailwindcss";

    And make sure src/main.tsx imports 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 old postcss.config.js that references tailwindcss or autoprefixer — it will conflict with the Vite plugin.
  • Astro projects: Put tailwindcss() inside vite: { plugins: [tailwindcss()] } in astro.config.mjs, and remove the deprecated @astrojs/tailwind integration.
  • 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.

Was this page helpful?

Still stuck? We answer every message ourselves. Write to us

Building with shadcn/ui and Tailwind CSS v4?

Install 188 free blocks and components with the shadcn CLI (no account), preview them in your own brand in Studio, or get all 1,570 blocks and every theme in UI Pro (€199 once).

Use it with

This page is built from UI Pro parts: the docs article block (docs-quernly) with the code, terminal, install command, steps, contents and feedback components, included in UI Pro.