Sub topic 12
When to use the PostCSS plugin instead
This chapter assumes you have a working Vite project with Tailwind CSS v4 installed through @tailwindcss/vite, and that you know what a PostCSS plugin is. Most Vite projects should keep the Vite plugin. The PostCSS plugin is for cases where you cannot use it.
Why the Vite plugin is the default
@tailwindcss/vite hooks into Vite directly. It sees which files Vite loads, so it can rebuild only what changed and give the fastest dev and build performance. The PostCSS plugin works one step removed. It runs on each CSS file that PostCSS processes, without that file-level knowledge from Vite.
Both plugins produce the same CSS from the same @import "tailwindcss"; line. The difference is where in your toolchain Tailwind runs.
When PostCSS is the better choice
Choose @tailwindcss/postcss when one of these applies:
- Your build tool has no Tailwind plugin. Webpack-based setups and some frameworks configure PostCSS but not Vite plugins.
- Your project already has a PostCSS pipeline you want to keep, such as one that runs other required plugins in a fixed order.
- A framework controls the CSS pipeline and only exposes a PostCSS config file.
If you use Vite and none of these apply, stay with the Vite plugin.
Set up the PostCSS plugin
Install the PostCSS package in place of the Vite one:
npm install tailwindcss @tailwindcss/postcss postcssCreate postcss.config.mjs in the project root:
export default {
plugins: {
"@tailwindcss/postcss": {},
},
}The CSS side does not change. Your main stylesheet still starts with:
@import "tailwindcss";If you are migrating from the Vite plugin, remove tailwindcss() from the plugins array in vite.config.ts. Vite reads postcss.config.mjs on its own, so nothing else needs registering. Keep only one of the two plugins active. Running both makes Tailwind process the same CSS twice.
What you no longer need
In v4 the PostCSS setup is shorter than in v3. You do not list autoprefixer or postcss-import, because the plugin handles vendor prefixes and @import resolution itself. A leftover v3-style config that names tailwindcss as a PostCSS plugin will fail, since that package no longer acts as one.
Common mistakes
| Symptom | Likely cause | Fix |
|---|---|---|
| Error saying `tailwindcss` is not a PostCSS plugin | v3 config still names `tailwindcss` | Replace it with `@tailwindcss/postcss` |
| Classes work but the build is slower than expected | Both plugins are active | Remove one of them |
| No styles at all | Config file name or location is wrong | Place `postcss.config.mjs` in the project root |
Exercise
Your Vite project already has tailwindcss() in vite.config.ts. You add postcss.config.mjs with @tailwindcss/postcss as well. What goes wrong, and what should you do?
Show answer
Both plugins process the same CSS, so Tailwind does the work twice, which can slow builds and cause confusing output. Keep only one: remove tailwindcss() from vite.config.ts if you need the PostCSS pipeline, or delete the PostCSS plugin entry if you want the Vite plugin.
Exercise
Name two situations where @tailwindcss/postcss is the better choice than @tailwindcss/vite.
Show answer
Any two of these: the build tool is not Vite and has no Tailwind plugin, the project must keep an existing PostCSS pipeline with other plugins in a set order, or a framework exposes only a PostCSS config for CSS processing.