Sub topic 3
Install tailwindcss and @tailwindcss/vite
This chapter covers the install step: what the two packages are, what the commands do, how to check the result, and which errors you are likely to see. It assumes you know basic HTML and CSS, have Node.js and npm installed, can run commands in a terminal, and know that Vite is a dev server and bundler. The next chapters cover the plugin configuration and the CSS import.
What you are installing
Tailwind CSS v4 ships as two npm packages that work together.
| Package | Role |
|---|---|
| `tailwindcss` | The core engine. It parses your CSS, finds class names in your files, and generates the CSS for the utilities you use. |
| `@tailwindcss/vite` | The first-party Vite plugin. It runs the core engine inside Vite's build pipeline, so Vite can process Tailwind directives in your CSS files. |
You need both. The core package alone does not hook into Vite. The plugin alone has nothing to run, because it relies on the core engine.
In v3, a typical setup needed four packages: tailwindcss, postcss, autoprefixer, and a tailwind.config.js file. In v4, the Vite plugin replaces the PostCSS and Autoprefixer setup for a typical project. Vendor prefixing and modern CSS handling are built into the engine.
Step 1: Create the Vite project
If you do not have a Vite project yet, create one. Skip this step if you already have one.
npm create vite@latest my-app
cd my-app
npm install tailwindcss @tailwindcss/viteThe first command starts an interactive prompt. It asks for a framework and a language variant. Any option works, because Tailwind operates on CSS and on the files that contain class names. The examples in this tutorial use plain JavaScript or TypeScript, but React, Vue, Svelte, and others follow the same steps.
The second command moves into the new folder. The third command installs the two Tailwind packages.
Note that npm create vite@latest does not install dependencies by itself. The third command runs npm install for the two named packages, and it also installs the project's existing dependencies listed in package.json. If you prefer, run a plain npm install first and the Tailwind install second. The result is the same.
Step 2: Understand what the install command does
npm install tailwindcss @tailwindcss/viteThis command does three things:
- It downloads both packages and their dependencies into
node_modules/. - It adds both names to the
dependenciessection ofpackage.json, with a version range such as^4.0.0. - It updates
package-lock.json, which pins the exact versions that were installed.
Open package.json afterward. You should see entries like this:
{
"dependencies": {
"@tailwindcss/vite": "^4.0.0",
"tailwindcss": "^4.0.0"
}
}The exact numbers depend on when you install. What matters is that the major version is 4 for both packages. If either shows 3, you have a version mismatch (see the troubleshooting section below).
Dependencies or devDependencies?
The command above puts both packages under dependencies. Many projects use -D (or --save-dev) instead:
npm install -D tailwindcss @tailwindcss/viteBoth work, because Tailwind runs at build time and the generated CSS is a static file. Use -D if your team keeps build tools under devDependencies. Use the plain form if you follow the Tailwind documentation exactly. Pick one and keep it consistent.
Keep the two versions aligned
The plugin and the core engine are released together. Keep them on the same major version, and preferably the same minor version. Upgrading one without the other is a common source of confusing errors. When you update, update both in one command:
npm install tailwindcss@latest @tailwindcss/vite@latestStep 3: Check that the install worked
Confirm that npm sees both packages at the expected version.
npm ls tailwindcss @tailwindcss/viteThe output is a dependency tree. A healthy result looks like this:
[email protected] /path/to/my-app
├─┬ @tailwindcss/[email protected]
│ └── [email protected] deduped
└── [email protected]The word deduped means the plugin reuses the single copy of tailwindcss that sits at the top of your project. That is the state you want. Two different tailwindcss versions in the tree can cause the plugin and the engine to disagree.
You can also check that the package files exist:
ls node_modules/@tailwindcss/viteIf the folder is missing, the install did not finish or failed.
Requirements for the install
The plugin runs inside Node.js, so Node.js must be a version that the packages support. Tailwind v4 and current Vite releases need a reasonably recent Node.js. Vite itself requires Node.js 18 or newer, and newer Vite releases raise that minimum. Check yours:
node --version
npm --versionIf the version is older than what Vite's current release requires, npm may print EBADENGINE warnings or the dev server may fail to start. Upgrade Node.js with your version manager or installer before you continue.
The plugin also works with a recent Vite version. If your project was created a long time ago with an old Vite, check the Tailwind documentation for the Vite versions the plugin supports and upgrade Vite if needed.
What the install does not do
The install only puts code on disk. It does not change your project's behavior yet. After this step:
- Vite does not know about Tailwind, because the plugin is not registered in
vite.config. - Your CSS does not contain any Tailwind directive.
- No utility classes exist in the output.
If you run the dev server now, your app looks exactly as it did before. That is expected. The next chapters add the plugin and the CSS import.
You also do not need to run any init command. In v3, npx tailwindcss init created a tailwind.config.js file. That command is not part of the v4 setup, and a config file is optional in v4. Customization moves into CSS, which a later chapter covers with @theme.
Setup flow
The diagram shows where the install sits in the full setup sequence.
Each step depends on the one before it. If a later step fails, go back and confirm that the earlier steps are complete. A missing install is the most common cause of an error in the config step.
Package managers
The commands above use npm. Other package managers install the same two packages.
| Manager | Command |
|---|---|
| npm | `npm install tailwindcss @tailwindcss/vite` |
| pnpm | `pnpm add tailwindcss @tailwindcss/vite` |
| Yarn | `yarn add tailwindcss @tailwindcss/vite` |
| Bun | `bun add tailwindcss @tailwindcss/vite` |
Use the manager your project already uses. Do not mix managers in one project. Each one writes its own lock file, and two lock files lead to different versions on different machines.
Common install problems
The plugin is not found
If you later see Cannot find module '@tailwindcss/vite', one of three things happened. The install failed, you ran it in the wrong folder, or you installed tailwindcss but forgot the plugin. Run npm ls @tailwindcss/vite from the project root. If npm reports (empty), run the install again.
Wrong folder
Run the install in the folder that contains package.json and vite.config. In a monorepo, install the packages in the workspace that owns the Vite app, not in the repository root. Check your location with pwd before you install.
Peer dependency errors
If npm prints ERESOLVE errors that mention Vite, the plugin does not support the Vite version in your project. Read the message. It names the version range the plugin accepts. Upgrade Vite to a supported version rather than forcing the install with --force or --legacy-peer-deps, because forced installs hide a real incompatibility.
Version 3 installed by accident
If npm ls tailwindcss shows version 3, an older range is pinned somewhere. Common causes are an existing tailwindcss@3 entry in package.json, or a copied snippet that specifies a version. Fix it by installing the latest explicitly:
npm install tailwindcss@latest @tailwindcss/vite@latestThen run npm ls tailwindcss again and confirm that only version 4 appears.
Old v3 packages left behind
When you migrate a v3 project, you may still have postcss, autoprefixer, and a postcss.config.js file. For a Vite-plugin setup you do not need them for Tailwind. A leftover PostCSS config that still lists tailwindcss as a plugin can break the build in v4, because that plugin entry moved to the separate @tailwindcss/postcss package. Remove the old Tailwind entry from the PostCSS config, or delete the file if it holds nothing else. A later chapter covers the PostCSS route and the full list of v3 differences.
Network and registry failures
Errors such as ETIMEDOUT, ENOTFOUND, or E401 point to network, proxy, or registry login problems, not to Tailwind. Check that npm config get registry returns the registry you expect, and that you are logged in if it is a private one.
Summary of the install step
- Install two packages:
tailwindcss(the engine) and@tailwindcss/vite(the plugin). - Both must be on major version 4, and should be updated together.
- The install changes
package.jsonand the lock file but does not change what your app does. - No
initcommand and notailwind.config.jsare needed. - Verify with
npm ls tailwindcss @tailwindcss/vite.
Exercises
Exercise
You run npm install tailwindcss only, and then add tailwindcss() imported from @tailwindcss/vite to your Vite config. What error do you expect, and what is the fix?
Show answer
Vite fails with an error such as Cannot find module '@tailwindcss/vite', because the plugin package was never installed. Run npm install tailwindcss @tailwindcss/vite (or just npm install @tailwindcss/vite) from the project root, then restart the dev server.
Exercise
npm ls tailwindcss shows [email protected] at the top level and a second [email protected] nested under @tailwindcss/vite. What is wrong, and how do you fix it?
Show answer
The project has two versions of the engine, and the top-level one is v3. This is a version mismatch. Install the latest of both packages with npm install tailwindcss@latest @tailwindcss/vite@latest, then run npm ls tailwindcss again and confirm that only a version 4 entry appears, shown as deduped under the plugin.
Exercise
After a successful install, you start the dev server and see no change in your page. Is the install broken?
Show answer
No. The install only places packages on disk. Vite does not use Tailwind until you register the plugin in vite.config and add @import "tailwindcss"; to your CSS. Those are the next steps.