Sub topic 2
Start from a Vite project
This chapter covers the starting point for the setup: a working Vite project that runs on your machine. You will create one, look at the files that matter for Tailwind, and confirm that the dev server runs before you add anything.
I assume you have these prerequisites:
- Basic HTML and CSS.
- Node.js and npm installed, and a terminal you are comfortable using.
- A rough idea of what Vite does: it serves your files during development and bundles them for production.
Why start from a clean project
Tailwind v4 needs a build tool to process your CSS. The Vite plugin used later in this tutorial hooks into Vite's pipeline. If Vite itself is broken, you cannot tell whether a problem comes from Tailwind or from the project. Check that the plain project works first. Then every later failure points to the step you just took.
Check your Node.js version
Vite needs a current Node.js release. Check what you have:
node --version
npm --versionThe Vite documentation lists the supported Node.js versions, and the Tailwind v4 toolchain is built for recent ones. If your version is old, upgrade Node.js before you continue. Many odd install errors come from an outdated runtime.
Create the project
Run the Vite scaffolding command:
npm create vite@latest my-appThe command asks you to pick a framework and a variant. For this tutorial, choose Vanilla and then JavaScript. The later examples use plain JavaScript and document.querySelector, so no framework code gets in the way. The Tailwind setup is the same for React, Vue, and other frameworks. Only the file names change.
Then install the dependencies and start the dev server:
cd my-app
npm install
npm run devVite prints a local address, usually http://localhost:5173/. Open it in a browser. You should see the default Vite starter page.
Know the files that matter
Stop at this point and look at the project layout. Tailwind will touch three places.
| File | Role in the Tailwind setup |
|---|---|
| `package.json` | Lists dependencies. The next chapter adds `tailwindcss` and `@tailwindcss/vite` here. |
| `vite.config.ts` or `vite.config.js` | Configures Vite. You will register the Tailwind plugin here. Some templates do not create this file, so you may need to add it yourself. |
| `src/style.css` | The stylesheet the app imports. You will replace its contents with the Tailwind import. |
The scaffold already has a src/main.js that imports ./style.css. This matters later. Tailwind only works if a CSS file that contains the Tailwind import is loaded by your app.
Tailwind will plug into the style.css step of this chain through Vite.
Common problems at this stage
npm create vite@latesthangs or fails. Check your network and your npm registry settings. The command downloads the scaffolding tool each time.- Port 5173 is busy. Vite picks the next free port and prints it. Use the address Vite shows.
- No
vite.configfile. Some templates omit it. This is fine. You will create it when you register the plugin.
Exercise
You finished the Tailwind steps, and the page shows no styling. Why is it useful to have confirmed earlier that the plain Vite project ran correctly?
Show answer
A working baseline shows that Node.js, npm, and the Vite dev server are fine. A failure after that point must come from the Tailwind steps, such as the install, the plugin registration, the CSS import, or the stylesheet import in the app. This narrows the search.