Installing Tailwind CSS
Tailwind CSS v4 can be installed in several ways depending on your build tool and project setup. Choose the method that works best for your workflow.Package Installation
Install Tailwind CSS from npm using your preferred package manager:Tailwind CSS v4.2.1 is the latest stable version. The framework requires Node.js 14.0 or higher.
Integration Methods
Tailwind CSS can be integrated into your project in multiple ways. Choose the method that best fits your build setup.Using the CLI
The Tailwind CLI is the simplest way to compile your CSS. Install the CLI package:package.json:
package.json
CLI Options
The Tailwind CLI supports several options:| Option | Alias | Description | Default |
|---|---|---|---|
--input | -i | Input CSS file | - |
--output | -o | Output CSS file | - (stdout) |
--watch | -w | Watch for changes and rebuild | false |
--minify | -m | Optimize and minify the output | false |
--optimize | - | Optimize without minifying | false |
--map | - | Generate source map | false |
--cwd | - | Current working directory | . |
Using with Vite
For Vite projects, install the Vite plugin:vite.config.ts:
vite.config.ts
The Vite plugin automatically detects whether to optimize CSS based on the
NODE_ENV environment variable.Vite Plugin Options
You can configure the Vite plugin with additional options:vite.config.ts
Using with PostCSS
For PostCSS-based build tools (like Next.js), install the PostCSS plugin:postcss.config.js:
postcss.config.js
PostCSS Plugin Options
Configure the PostCSS plugin with options:postcss.config.js
Using with Webpack
For Webpack projects, install the Webpack plugin:Create Your CSS File
Create a CSS file that imports Tailwind’s styles:The
@import 'tailwindcss'; statement imports all of Tailwind’s base styles, utilities, and default theme. This is the simplest way to get started.Import the CSS
Import your compiled CSS file in your application:Platform-Specific Packages
Tailwind CSS provides optimized native binaries for different platforms:@tailwindcss/node- Node.js runtime@tailwindcss/browser- Browser runtime (WASM)@tailwindcss/oxide- Rust-powered scanning engine
Next Steps
Quick Start Guide
Follow the quickstart guide to build your first component with Tailwind CSS.
Editor Setup
Set up IntelliSense in your editor for autocomplete and linting.
Learn Core Concepts
Understand Tailwind’s utility-first approach and design philosophy.
Troubleshooting
CSS Not Updating
If your CSS isn’t updating when you make changes:- Ensure you’re using the
--watchflag with the CLI - Check that your source files are in the correct directory
- Restart your development server
Build Performance
For faster builds in large projects:- Use the
@tailwindcss/oxidescanner (included by default in v4) - Limit the scope of source file scanning with
@sourcedirectives - Enable Lightning CSS optimization only in production