Sub topic 7
Run the dev server and verify utility classes
This chapter assumes you have finished the earlier setup steps. You have a Vite project with tailwindcss and @tailwindcss/vite installed. The plugin is registered in vite.config.ts. Your main CSS file contains @import "tailwindcss";, and your app entry imports that file. You also need Node.js, npm, and a terminal.
The goal here is to prove the whole chain works. You will start the dev server, render an element with utility classes, and check in the browser that Tailwind generated the CSS for them. You will also learn how to tell a working setup from a silent failure.
What "working" means
Tailwind v4 does not ship a fixed stylesheet that contains every class. It generates CSS on demand. The Vite plugin reads your source files, finds class names that look like utilities, and emits CSS only for those. So "Tailwind works" means three things are true at once:
- Vite loads your CSS file and the plugin processes
@import "tailwindcss";. - The plugin finds the class names you used in your files.
- The generated rules reach the browser and match your elements.
A failure at any step looks the same on screen: the text is unstyled. That is why it helps to check each step separately.
Start the dev server
From the project root, run the dev script that Vite created:
npm run devVite prints a local address, usually http://localhost:5173/. Open it in a browser. If the port is busy, Vite picks the next free one and prints it. Always use the address from the terminal output, not one you remember.
Leave the server running. Vite uses hot module replacement (HMR), so it pushes changes to the browser without a full reload when you save a file.
Add a test element
Your entry file should import the stylesheet and render something with utility classes. Use the example from the earlier chapter:
import './style.css'
document.querySelector('#app').innerHTML = `
<h1 class="text-3xl font-bold underline text-blue-600">Hello Tailwind</h1>
`This assumes the CSS file is named style.css and sits next to the entry file, and that your index.html contains an element with id="app". If your file names differ, adjust the import path. The default Vite vanilla template already has #app.
The four classes do the following:
| Class | Effect |
|---|---|
| `text-3xl` | Sets a large font size and a matching line height. |
| `font-bold` | Sets font weight to 700. |
| `underline` | Adds an underline through `text-decoration-line`. |
| `text-blue-600` | Sets the text color from the default blue palette. |
If the heading appears large, bold, underlined, and blue, the setup works.
Check the result in the browser
A visual check is quick, but it can mislead. Vite's default template CSS may already style headings, and a blue color could come from somewhere else. Confirm with the developer tools.
- Right-click the heading and choose Inspect.
- In the Elements panel, confirm the
classattribute lists your four classes. - In the Styles panel, look for rules such as
.text-3xl,.font-bold,.underline, and.text-blue-600. - Check the source file shown next to each rule. It should point to your
style.css, processed by Vite.
In v4, the generated rules are placed inside cascade layers. You will see them grouped under names like @layer utilities. Tailwind v4 relies on native CSS cascade layers, so this is expected and not a sign of a problem.
Colors in v4's default palette are defined with the oklch() color function. If you read the computed color of text-blue-600, you will see an oklch(...) value rather than a hex code. That is normal.
Prove that Tailwind is generating classes on demand
Edit the heading while the server runs. Change text-blue-600 to text-red-600 and save:
import './style.css'
document.querySelector('#app').innerHTML = `
<h1 class="text-3xl font-bold underline text-red-600">Hello Tailwind</h1>
`The heading should turn red without a manual refresh. This shows that the plugin re-scanned your file, found a class it had not generated before, and produced the new rule. If the color changes, step 2 of the chain (detection) and step 3 (delivery) both work.
You can also test a value that exists in no default palette, using an arbitrary value in square brackets:
import './style.css'
document.querySelector('#app').innerHTML = `
<h1 class="text-3xl font-bold underline text-[#0f766e]">Hello Tailwind</h1>
`Tailwind generates color: #0f766e for this class on the fly. Arbitrary values are a good test because they cannot come from any prebuilt file.
Read the terminal and the network tab
The terminal tells you about build errors. A healthy start prints a Vite banner and the local URL. An error in your CSS or plugin configuration appears here and also as an overlay in the browser.
The network tab helps when styles are missing. Reload the page with the Network panel open and filter by CSS. In dev mode Vite usually serves your stylesheet through a JavaScript module. If you imported the CSS from your entry file, you will see a request for style.css (sometimes with a ?t= query on updates). If you see no request for it, the import is missing or the entry file is not loaded. Open the Sources tab or the request itself to read the generated CSS. It should be far longer than the one line you wrote, because it contains Tailwind's theme variables, base styles, and the utilities it found.
Common ways the check fails
Most failures at this stage come from a short list of causes.
| Symptom | Likely cause | Fix |
|---|---|---|
| Heading is plain black text | `style.css` is never imported | Add `import './style.css'` to the entry file. |
| Heading is plain, no CSS request in Network tab | Wrong import path or wrong entry script in `index.html` | Check that `index.html` loads the file that contains the import. |
| Base styles apply but utilities are missing | The plugin is not registered, or the class is not detected | Check `vite.config.ts` and that the class appears as a complete string in a scanned file. |
| Terminal error about an unknown at-rule or import | CSS contains v3 directives such as `@tailwind base;` | Replace them with `@import "tailwindcss";`. |
| Config changes have no effect | The dev server was not restarted after editing `vite.config.ts` | Stop the server and run `npm run dev` again. |
Restarting the server matters. Vite watches your source and CSS files, but it reloads plugin configuration only when the server restarts. Vite often restarts itself when vite.config.ts changes, but do not count on that. If a config edit seems ignored, restart manually.
A quick check that also works for components
Once the heading works, test a few more utilities that cover different parts of the engine. This confirms that more than the first few classes are generated:
import './style.css'
document.querySelector('#app').innerHTML = `
<main class="mx-auto max-w-md p-6">
<h1 class="text-3xl font-bold text-blue-600">Hello Tailwind</h1>
<p class="mt-2 text-gray-600 hover:text-gray-900">Hover over this paragraph.</p>
<button class="mt-4 rounded-lg bg-blue-600 px-4 py-2 text-white hover:bg-blue-700 focus:outline-2 focus:outline-offset-2 focus:outline-blue-600">
Save
</button>
</main>
`This covers spacing (mt-2, p-6, px-4), layout (mx-auto, max-w-md), shape and color (rounded-lg, bg-blue-600), and variants (hover:, focus:). Hover the paragraph and the button. If the colors change, variants work too. Tab to the button to see the focus outline.
Why a plain `npm run dev` is enough
You did not run a separate Tailwind command or watcher. In v3 setups using the CLI, you often ran one process to build CSS and another for the app. In v4 with the Vite plugin, Vite owns the pipeline. The plugin hooks into Vite's module graph, so when a scanned file changes, Vite invalidates the CSS module and sends an update to the browser. One command covers everything.
Summary of the verification routine
When you set up a new project, follow the same short routine:
- Run
npm run devand open the printed URL. - Render an element with several utility classes.
- Inspect it and confirm the rules come from your processed
style.css. - Change a class and save, then confirm the page updates without a manual reload.
- If anything fails, use the table above to identify which link in the chain broke.
Exercise
You added class="text-3xl font-bold" to an element and the page shows unstyled text. In the Network tab, no request for style.css appears. Which link in the chain has failed, and what should you check first?
Show answer
The first link has failed: Vite is not loading the stylesheet at all, so the plugin never processes it. Check that the entry script loaded by index.html contains import './style.css' (or the correct path to your CSS file). The Tailwind plugin and class detection cannot be at fault yet, because the CSS file was never requested.
Exercise
Your code builds a class with const cls = "bg-" + color + "-500" and the background never appears for color = "green". Why, and how do you fix it?
Show answer
Tailwind scans files as plain text and never evaluates JavaScript, so the complete token bg-green-500 never appears in the source and no rule is generated. Fix it by writing complete class names, for example a lookup object such as { green: "bg-green-500", red: "bg-red-500" }, and select from it with color.