Sub topic 7
Run the dev server and verify utility classes
This chapter assumes you finished the previous steps: tailwindcss and @tailwindcss/vite are installed, the plugin is registered in vite.config.ts, and your CSS file contains @import "tailwindcss";. You should also be comfortable with a terminal and with browser DevTools.
Confirm the entry file
The stylesheet only takes effect if your app imports it. In the Vite vanilla template, src/main.js is the entry. It should look like this:
import './style.css'
document.querySelector('#app').innerHTML = `
<h1 class="text-3xl font-bold underline text-blue-600">Hello Tailwind</h1>
`The import './style.css' line makes Vite pass the CSS through the Tailwind plugin. The <h1> uses four utility classes: text-3xl sets a large font size, font-bold sets bold weight, underline underlines the text, and text-blue-600 sets a blue color.
Start the dev server
From the project root, run:
npm run devVite prints a local address, usually http://localhost:5173/. Open it in your browser.
What you should see
The heading "Hello Tailwind" should be large, bold, underlined, and blue. If it appears as small black text in the browser's default serif or sans-serif font, Tailwind is not being applied. See the checks below.
Verify in DevTools
Seeing blue text is a good sign, but you can check the details too.
- Right-click the heading and choose Inspect.
- In the Styles panel, find rules such as
.text-3xland.text-blue-600. - Confirm that each rule matches a class on the element.
Tailwind generates CSS only for classes it finds in your files. If you search the served stylesheet, you will see .text-3xl but not a class like .text-9xl that you never used.
Test live updates
Keep the dev server running and edit the heading's classes, for example change text-blue-600 to text-red-600. Save the file. Vite updates the page without a full reload, and the heading turns red. This confirms that Tailwind rescans your files as they change.
Common failures
| Symptom | Likely cause | Fix |
|---|---|---|
| Heading has no styling | `style.css` is not imported | Add `import './style.css'` to the entry file |
| Heading has no styling, no error | Plugin missing from the config | Check that `tailwindcss()` is in the `plugins` array |
| Build error about an unknown module | Packages not installed | Run `npm install tailwindcss @tailwindcss/vite` |
| Raw `@tailwind` directives or errors | v3 syntax in the CSS | Replace them with `@import "tailwindcss";` |
| New class has no effect | File is outside the scanned paths | Covered in a later chapter on `@source` |
After changing vite.config.ts, stop the server with Ctrl+C and run npm run dev again. Vite does not apply config changes to a running server.
Exercise
You run npm run dev, open the page, and the heading is unstyled. DevTools shows no .text-3xl rule anywhere. Name two things to check first.
Show answer
Check that the entry file imports the stylesheet (import './style.css'), and that tailwindcss() is listed in the plugins array of vite.config.ts (restarting the dev server after any config change). Also confirm the CSS file contains @import "tailwindcss";.