Sub topic 3
Check browser support and finish a Tailwind v4 setup
Assume you know basic CSS, npm commands, and how Vite serves and bundles a project. This chapter covers the checks after the initial Tailwind v4 setup.
Check browser support
Tailwind v4 relies on modern CSS features such as cascade layers, @property, and color-mix(). Check the current Tailwind browser-support table before supporting older browsers. A browser that cannot parse these features may ignore part of the generated stylesheet.
| Requirement | Action |
|---|---|
| Modern browser | Test the application in your supported browsers |
| Older browser support | Consider Tailwind v3 or a compatibility strategy |
| Production confidence | Test the built application, not only Vite's development server |
Customize design tokens with `@theme`
Tailwind v4 uses CSS-first configuration. A design token is a named value, such as a color or font, that utilities can reuse.
@import "tailwindcss";
@theme {
--color-brand: #3b82f6;
--font-display: "Georgia", serif;
}This makes utilities such as bg-brand, text-brand, and font-display available. Keep class names complete in source files so Tailwind can detect them.
How Tailwind finds your classes, and `@source`
Tailwind automatically scans project files for class-like text. It generates CSS for detected utilities instead of shipping every possible utility. Classes assembled dynamically, such as "text-" + color, may not be detected. Use complete class strings or safelist-like source files explicitly.
@import "tailwindcss";
@source "../node_modules/@my-company/ui-lib";The path is relative to this CSS file. Use @source when a dependency contains classes that Tailwind's automatic detection does not scan.
Build for production
Run the project’s build script:
npm run buildVite processes the CSS and emits optimized assets. Test the files in dist with your deployment setup.
When to use the PostCSS plugin instead
Use @tailwindcss/vite for a Vite project. Use @tailwindcss/postcss when another build system already owns the PostCSS pipeline.
export default {
plugins: {
"@tailwindcss/postcss": {},
},
};Differences from v3 setup
- Import Tailwind with
@import "tailwindcss";. - A
tailwind.config.jsfile is not required for typical v4 projects. - The Vite plugin replaces the usual v3 PostCSS setup.
@themereplaces much configuration that previously lived in JavaScript.
Troubleshooting common problems
- No styles: confirm the CSS file is imported by the application entry file.
- Unknown custom utility: check the
@themevariable name and restart Vite. - Dependency classes missing: add an appropriate
@sourcepath. - Dynamic classes missing: use complete class names in source code.
- Build differs from development: run
npm run buildand inspect the generated assets.
Exercise
A component library's classes are missing from the production build. What should you check first?
Show answer
Confirm the library path is included with an @source directive and that its classes are written as complete, detectable class strings.