Tailwind CSS
Tailwind CSS is a highly popular, utility-first CSS framework designed for rapidly building custom user interfaces directly in your markup. The current stable release series is v4.2.2, which represents a significant architectural shift with a new, faster Rust-based engine (Oxide and Lightning CSS) for processing CSS. It has an active release cadence with frequent patch and minor updates. Key differentiators for v4 include its move towards a "CSS-first" configuration model, where customization is primarily handled within CSS files using `@theme` directives, and automatic content detection, simplifying the build process. Unlike previous versions, Tailwind CSS v4 no longer requires PostCSS for its core compilation, as it integrates its own CSS processing pipeline. Dedicated bundler plugins like `@tailwindcss/vite` and `@tailwindcss/webpack` are provided for seamless integration into modern build ecosystems, while still offering a PostCSS compatibility layer via `@tailwindcss/postcss` for existing setups. This version emphasizes performance, a smaller footprint, and leverages modern CSS features like native cascade layers and `color-mix()` for enhanced capabilities and developer experience.
Common errors
-
Error: "tailwindcss" is not a PostCSS plugin.
cause Attempting to use `require('tailwindcss')` directly as a PostCSS plugin in v4, or missing `@tailwindcss/postcss` package.fixFor PostCSS integration, ensure `@tailwindcss/postcss` is installed and used in your `postcss.config.js` (e.g., `plugins: { tailwindcss: {} }` or `plugins: { '@tailwindcss/postcss': {} }`). -
tailwindcss: command not found
cause The Tailwind CSS CLI is not installed or not accessible in your system's PATH.fixEnsure `tailwindcss` is installed as a development dependency (`npm install -D tailwindcss`) and run the command using `npx tailwindcss` or add your `node_modules/.bin` directory to your PATH. -
No utility classes were generated. Ensure your content config is correct.
cause While v4 has automatic content detection, this error can still occur if template files are in non-standard locations, or if the auto-detection heuristics fail for specific project structures.fixReview your project structure. If issues persist, refer to the official documentation for manual content configuration options within the v4 CSS-first approach, or consider providing explicit paths if necessary, although this is generally not required for v4. -
Unknown @import rule: "tailwindcss"
cause The `@import 'tailwindcss';` directive in your CSS file is not being processed by the Tailwind CSS PostCSS plugin (if using PostCSS) or the Tailwind CSS CLI is not set up correctly to parse it.fixEnsure your build process correctly pipes your CSS through the Tailwind CSS v4 engine. If using PostCSS, verify `@tailwindcss/postcss` is correctly configured in `postcss.config.js` and that PostCSS is applied to your CSS files. If using the CLI, ensure it targets the correct input CSS file containing the `@import`.
Warnings
- breaking Tailwind CSS v4.0 introduces a "CSS-first" configuration, deprecating the `tailwind.config.js` file for theme customization. All theme and plugin configurations are now primarily handled directly within your main CSS file using the `@theme` directive.
- breaking The `@tailwind base; @tailwind components; @tailwind utilities;` directives are no longer supported in Tailwind CSS v4. They must be replaced by a single `@import 'tailwindcss';` statement in your main CSS entry point.
- breaking Tailwind CSS v4 no longer ships its core compilation as a PostCSS plugin within the `tailwindcss` package. To use Tailwind v4 with PostCSS, you must install and configure the new dedicated `@tailwindcss/postcss` plugin. Additionally, `autoprefixer` and `postcss-import` are no longer needed as their functionalities are built directly into the v4 engine.
- breaking Existing custom JavaScript plugins created for Tailwind CSS v3 are likely incompatible with v4's new Rust-based engine and CSS-first configuration. The plugin API has been significantly revised.
- gotcha Tailwind CSS v4 is designed for modern browsers (Safari 16.4+, Chrome 111+, Firefox 128+) and leverages cutting-edge CSS features like cascade layers, registered custom properties (`@property`), and `color-mix()`. This means it will not work or degrade poorly in older browsers.
- gotcha Tailwind CSS v4 is a full-featured CSS build tool and is not designed to be used with CSS preprocessors like Sass, Less, or Stylus. It handles imports, vendor prefixing, and nesting internally, rendering external preprocessors redundant or conflicting.
Install
-
npm install tailwindcss -
yarn add tailwindcss -
pnpm add tailwindcss
Imports
- tailwindcss
import tailwindcss from 'tailwindcss'
import tailwindcss from '@tailwindcss/postcss'
- plugin
const plugin = require('tailwindcss/plugin')import plugin from 'tailwindcss/plugin'
- Tailwind CSS in CSS
@tailwind base; @tailwind components; @tailwind utilities;
@import 'tailwindcss';
Quickstart
```typescript
// 1. Install necessary packages
// npm install -D tailwindcss @tailwindcss/postcss postcss
// 2. Create your main CSS file (e.g., src/input.css)
// This file now contains your Tailwind import and any CSS-first configurations.
// src/input.css
/*
@import 'tailwindcss';
@theme {
--color-brand-500: oklch(0.68 0.28 274);
--font-body: ui-sans-serif, system-ui, sans-serif;
--space-xxs: 0.25rem;
--space-xs: 0.5rem;
--space-sm: 0.75rem;
}
*/
// 3. Create a PostCSS configuration file (e.g., postcss.config.mjs)
// This registers Tailwind CSS v4 as a PostCSS plugin.
// postcss.config.mjs
import tailwindcss from '@tailwindcss/postcss';
export default {
plugins: {
tailwindcss: {},
},
};
// 4. Create an HTML file (e.g., public/index.html)
// public/index.html
/*
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tailwind CSS v4 Quickstart</title>
<link rel="stylesheet" href="/output.css">
</head>
<body>
<h1 class="text-brand-500 font-bold text-5xl p-xs">Hello, Tailwind v4!</h1>
<p class="text-body text-sm px-sm">This is a paragraph with custom theme colors and spacing.</p>
</body>
</html>
*/
// 5. Add a build script to your package.json
// The 'tailwindcss' command line tool processes your CSS.
// package.json
/*
{
"name": "my-tailwind-app",
"version": "1.0.0",
"scripts": {
"build:css": "tailwindcss -i ./src/input.css -o ./public/output.css --watch"
},
"devDependencies": {
"tailwindcss": "^4.2.2",
"@tailwindcss/postcss": "^4.2.2",
"postcss": "^8.4.38"
}
}
*/
// 6. Run the build command and open public/index.html
// npm run build:css
```