Sub topic 3
Install tailwindcss and @tailwindcss/vite
This chapter assumes you have Node.js and npm installed, can run commands in a terminal, and know that Vite is a dev server and bundler. You should also have a Vite project, or be ready to create one in the next step.
What you are installing
Tailwind CSS v4 splits into two packages for a Vite project:
| Package | Role |
|---|---|
| `tailwindcss` | The core engine. It reads your CSS and your source files, then generates the utility classes you use. |
| `@tailwindcss/vite` | The first-party Vite plugin. It runs the engine inside Vite's pipeline, so you need no separate PostCSS step. |
Both are build-time tools, so npm will record them in your project's dependencies. The plugin is what lets a typical v4 project work without a tailwind.config.js file or a postcss.config file.
Create the project and install
If you don't have a Vite project yet, create one. Then move into the project folder and install both packages.
npm create vite@latest my-app
cd my-app
npm install tailwindcss @tailwindcss/viteThe create vite command asks you to pick a framework and a language. Any option works for this tutorial. The npm install line adds both packages in one command.
Notice what is missing. There is no npx tailwindcss init step. In v3 that command generated a config file. In v4 the configuration lives in your CSS, which later chapters cover.
How the pieces connect
The install only puts the code on disk. Nothing uses it until you register the plugin and import Tailwind in CSS. The diagram shows the order of the setup.
Check that the install worked
Before you move on, confirm that npm recorded both packages. Open package.json and look at the dependencies section. You should see entries similar to these, though your version numbers will differ:
{
"dependencies": {
"@tailwindcss/vite": "^4.0.0",
"tailwindcss": "^4.0.0"
}
}You can also ask npm directly:
npm ls tailwindcss @tailwindcss/viteThe command prints a tree that lists both packages and their installed versions. Both should start with 4. If either shows 3, you have an older release, and the later steps won't match.
Common install problems
- The wrong major version. An old lockfile or a pinned version can leave you on v3. Run
npm install tailwindcss@latest @tailwindcss/vite@latestto move both forward. - Mismatched versions. Keep
tailwindcssand@tailwindcss/viteon the same major version. The plugin calls into the core engine, so a mismatch can fail in confusing ways. - Installing in the wrong folder. If you run
npm installoutside the project, npm creates or edits a differentpackage.json. Check that your terminal is insidemy-appfirst. - Installing only one package. The plugin does not replace the core package. You need both.
What comes next
At this point your project has the packages, but Vite does not know about them yet. The next chapter adds the plugin to vite.config.ts. After that, a single CSS import turns Tailwind on.
Exercise
You run npm ls tailwindcss @tailwindcss/vite and the output shows [email protected] next to @tailwindcss/[email protected]. What is wrong, and what command do you run to fix it?
Show answer
The two packages are on different major versions, and the core package is still v3. Run npm install tailwindcss@latest @tailwindcss/vite@latest so both move to v4, then run npm ls again to confirm both versions start with 4.
Exercise
Why does a typical v4 Vite project not need postcss or autoprefixer in its install command?
Show answer
The @tailwindcss/vite plugin runs Tailwind inside Vite directly, and it handles CSS imports and vendor prefixes itself. A separate PostCSS pipeline is only needed when you use the @tailwindcss/postcss plugin instead.