Setup
In this chapter, you set up a Tailwind CSS v4 development environment.
Supported browsers
Tailwind CSS v4 supports the following browsers.
- Safari 16.4 or later
- Chrome 111 or later
- Firefox 128 or later
v4 depends on modern CSS features such as @property and color-mix(), so it does not work in older browsers.
On these browser versions, all the modern CSS features covered in this guide (container queries, the :has() selector, the svh/dvh viewport units, the oklch color space, etc.) are supported. As long as you target a v4-supported browser, you do not need to worry about compatibility for individual features.
Setting up in a Vite project
Creating the project
npm create vite@latest tailwind-project -- --template react-ts
cd tailwind-project
npm install
Installing Tailwind CSS
npm install -D tailwindcss @tailwindcss/vite
Updating the Vite config
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'
export default defineConfig({
plugins: [react(), tailwindcss()],
})
Configuring the CSS file
@import "tailwindcss";
Checking that it works
function App() {
return (
<div className="min-h-screen bg-gray-100 flex items-center justify-center">
<h1 className="text-4xl font-bold text-blue-600">
Hello Tailwind CSS!
</h1>
</div>
)
}
export default App
Start the dev server.
npm run dev
Setting up with PostCSS
If you do not use the Vite plugin, use the PostCSS plugin.
Installation
npm install -D tailwindcss @tailwindcss/postcss postcss
PostCSS config
export default {
plugins: {
'@tailwindcss/postcss': {},
},
}
CSS file
@import "tailwindcss";
Setting up with the CLI
If you use it without a build tool, use the CLI.
Installation
npm install -D tailwindcss @tailwindcss/cli
Creating the input CSS
@import "tailwindcss";
Build command
npx @tailwindcss/cli -i src/input.css -o dist/output.css --watch
Using the CDN (for development)
For prototyping or learning, you can also use the CDN.
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
</head>
<body>
<h1 class="text-3xl font-bold text-blue-500">Hello!</h1>
</body>
</html>
The CDN build is not recommended for production. Limit it to development and prototyping.
VS Code extension
Tailwind CSS IntelliSense
The official extension, which provides the following features.
- Autocomplete for class names
- CSS preview on hover
- Syntax error detection
- Syntax highlighting
Installation:
- Open the Extensions panel in VS Code
- Search for "Tailwind CSS IntelliSense"
- Install it
Recommended settings
{
"tailwindCSS.experimental.classRegex": [
["clsx\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)"]
],
"editor.quickSuggestions": {
"strings": true
}
}
Prettier integration
For automatic class sorting, use the Prettier plugin.
npm install -D prettier prettier-plugin-tailwindcss
{
"plugins": ["prettier-plugin-tailwindcss"]
}
Project structure
A recommended project structure.
project/
├── src/
│ ├── components/
│ │ ├── Button.tsx
│ │ └── Card.tsx
│ ├── index.css # @import "tailwindcss"
│ ├── App.tsx
│ └── main.tsx
├── vite.config.ts
├── postcss.config.js # When using PostCSS
└── package.json
Preparing for production
Build command
npm run build
At build time, Tailwind CSS v4 emits only the classes used in your project into the CSS.
In v3 you had to specify the files to scan with a content array in tailwind.config.js. In v4, the Vite plugin or @tailwindcss/postcss detects your source files automatically, so no manual configuration is needed.
A guideline for build size
For a typical project, the production CSS is around 10–30 KB after gzip. Unused classes are removed automatically, so no matter how many utilities you try out during development, it does not affect the final file size.
Framework-specific setup notes (Next.js / Nuxt)
Next.js
npm install tailwindcss @tailwindcss/postcss postcss
export default {
plugins: {
"@tailwindcss/postcss": {},
},
};
@import "tailwindcss";
Nuxt
npm install tailwindcss @tailwindcss/vite
import tailwindcss from "@tailwindcss/vite";
export default defineNuxtConfig({
css: ["~/assets/css/main.css"],
vite: {
plugins: [tailwindcss()],
},
});
@import "tailwindcss";
The @nuxtjs/tailwindcss module depends on the Tailwind CSS v3 line, so for v4 you use the @tailwindcss/vite plugin directly, as in the official instructions.
Summary
- Configure Tailwind CSS v4 with the Vite plugin or PostCSS
- Import it with
@import "tailwindcss" - Boost your development efficiency with the VS Code extension
- Auto-sort classes with the Prettier plugin
- Supported browsers: Chrome 111+, Safari 16.4+, Firefox 128+
- Unused CSS is removed automatically in the production build
What to read next
- The utility-first mindset — the core philosophy of Tailwind
- Flexbox layout — actually build a layout
- Introduction to React — Tailwind CSS — patterns for combining with React
- Tailwind CSS Guide table of contents — back to the structure of all 18 chapters