Sub topic 1
Installing Tailwind CSS v4 with Vite
Prerequisites
Assume you know basic HTML and CSS, can run npm commands, and understand that Vite is a development server and build tool. You also need Node.js and npm installed.
What changes in Tailwind v4
Tailwind CSS v4 uses a CSS-first setup. A typical Vite project no longer needs tailwind.config.js, separate @tailwind directives, or manual PostCSS configuration. You import Tailwind directly in your CSS:
@import "tailwindcss";The first-party @tailwindcss/vite plugin connects Tailwind to Vite. It detects class names, generates only the required CSS, and integrates with Vite's development and production builds.
>callout note > Tailwind v4's default workflow is simpler than v3's. Do not copy v3 setup instructions that add @tailwind base, @tailwind components, and @tailwind utilities unless a project specifically requires the older version.
Start from a Vite project
Create a project with Vite's scaffolding command. Choose a framework and language when prompted, or use the defaults:
npm create vite@latest my-app
cd my-appThe project must have a CSS entry file and a Vite configuration file, usually vite.config.js or vite.config.ts.
Install the packages
Install Tailwind and its Vite integration:
npm install tailwindcss @tailwindcss/vitetailwindcss contains the framework. @tailwindcss/vite is the plugin that lets Vite process it.
Add the plugin to `vite.config`
Register the plugin beside any existing Vite plugins. For a TypeScript configuration:
import { defineConfig } from 'vite'
import tailwindcss from '@tailwindcss/vite'
export default defineConfig({
plugins: [
tailwindcss(),
],
})Keep existing plugins in the array. The plugin is now ready, but the next step is importing Tailwind from the stylesheet that your application loads.
Exercise
Which package connects Tailwind CSS v4 to Vite?
Show answer
The @tailwindcss/vite package provides the Vite plugin.