{"id":12117,"library":"tailwindcss","title":"Tailwind CSS","description":"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.","status":"active","version":"4.2.2","language":"javascript","source_language":"en","source_url":"https://github.com/tailwindlabs/tailwindcss","tags":["javascript"],"install":[{"cmd":"npm install tailwindcss","lang":"bash","label":"npm"},{"cmd":"yarn add tailwindcss","lang":"bash","label":"yarn"},{"cmd":"pnpm add tailwindcss","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for integrating Tailwind CSS v4 as a PostCSS plugin into existing PostCSS-based build pipelines.","package":"@tailwindcss/postcss","optional":true},{"reason":"Peer dependency for `@tailwindcss/postcss` if integrating with PostCSS.","package":"postcss","optional":true},{"reason":"Required for direct integration with Vite as a plugin.","package":"@tailwindcss/vite","optional":true},{"reason":"Required for direct integration with Webpack as a plugin.","package":"@tailwindcss/webpack","optional":true}],"imports":[{"note":"Since v4, the main `tailwindcss` package is no longer a PostCSS plugin. Use `@tailwindcss/postcss` for PostCSS integration.","wrong":"import tailwindcss from 'tailwindcss'","symbol":"tailwindcss","correct":"import tailwindcss from '@tailwindcss/postcss'"},{"note":"Used for creating custom Tailwind CSS plugins. While the core configuration is now CSS-first in v4, JavaScript plugins are still supported via this import.","wrong":"const plugin = require('tailwindcss/plugin')","symbol":"plugin","correct":"import plugin from 'tailwindcss/plugin'"},{"note":"In Tailwind CSS v4, the old `@tailwind` directives are replaced by a single `@import` statement in your main CSS file.","wrong":"@tailwind base; @tailwind components; @tailwind utilities;","symbol":"Tailwind CSS in CSS","correct":"@import 'tailwindcss';"}],"quickstart":{"code":"```typescript\n// 1. Install necessary packages\n// npm install -D tailwindcss @tailwindcss/postcss postcss\n\n// 2. Create your main CSS file (e.g., src/input.css)\n// This file now contains your Tailwind import and any CSS-first configurations.\n// src/input.css\n/*\n@import 'tailwindcss';\n\n@theme {\n  --color-brand-500: oklch(0.68 0.28 274);\n  --font-body: ui-sans-serif, system-ui, sans-serif;\n  --space-xxs: 0.25rem;\n  --space-xs: 0.5rem;\n  --space-sm: 0.75rem;\n}\n*/\n\n// 3. Create a PostCSS configuration file (e.g., postcss.config.mjs)\n// This registers Tailwind CSS v4 as a PostCSS plugin.\n// postcss.config.mjs\nimport tailwindcss from '@tailwindcss/postcss';\n\nexport default {\n  plugins: {\n    tailwindcss: {},\n  },\n};\n\n// 4. Create an HTML file (e.g., public/index.html)\n// public/index.html\n/*\n<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n  <meta charset=\"UTF-8\">\n  <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n  <title>Tailwind CSS v4 Quickstart</title>\n  <link rel=\"stylesheet\" href=\"/output.css\">\n</head>\n<body>\n  <h1 class=\"text-brand-500 font-bold text-5xl p-xs\">Hello, Tailwind v4!</h1>\n  <p class=\"text-body text-sm px-sm\">This is a paragraph with custom theme colors and spacing.</p>\n</body>\n</html>\n*/\n\n// 5. Add a build script to your package.json\n// The 'tailwindcss' command line tool processes your CSS.\n// package.json\n/*\n{\n  \"name\": \"my-tailwind-app\",\n  \"version\": \"1.0.0\",\n  \"scripts\": {\n    \"build:css\": \"tailwindcss -i ./src/input.css -o ./public/output.css --watch\"\n  },\n  \"devDependencies\": {\n    \"tailwindcss\": \"^4.2.2\",\n    \"@tailwindcss/postcss\": \"^4.2.2\",\n    \"postcss\": \"^8.4.38\"\n  }\n}\n*/\n\n// 6. Run the build command and open public/index.html\n// npm run build:css\n```","lang":"typescript","description":"Demonstrates a basic setup for Tailwind CSS v4.2.2 using the new CSS-first configuration, `@tailwindcss/postcss` plugin, and the CLI to generate CSS. It includes custom theme variables defined via the `@theme` directive."},"warnings":[{"fix":"Migrate your `tailwind.config.js` settings to the new `@theme` syntax within your main CSS file (e.g., `src/input.css`). Refer to the official v4 migration guide for detailed steps, or use the `@tailwindcss/upgrade` tool.","message":"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.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Update your primary CSS file (e.g., `src/input.css`) to use `@import 'tailwindcss';` instead of the three separate `@tailwind` directives.","message":"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.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Install `@tailwindcss/postcss` and update your `postcss.config.js` to reference `tailwindcss: {}` (or `@tailwindcss/postcss: {}` if explicit). Remove `autoprefixer` and `postcss-import` from your PostCSS configuration and `devDependencies`.","message":"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.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Review and rewrite custom plugins according to the new v4 plugin API documentation. Use the `@tailwindcss/upgrade` tool, but be prepared for manual adjustments in complex plugin scenarios.","message":"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.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"If supporting older browsers is critical, consider sticking to Tailwind CSS v3.4.x. For v4 projects, ensure your target browser list is compatible with modern CSS features.","message":"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.","severity":"gotcha","affected_versions":">=4.0.0"},{"fix":"Remove Sass, Less, or Stylus from your build pipeline when using Tailwind CSS v4. Leverage Tailwind's built-in capabilities for imports and nesting directly in CSS.","message":"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.","severity":"gotcha","affected_versions":">=4.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"For PostCSS integration, ensure `@tailwindcss/postcss` is installed and used in your `postcss.config.js` (e.g., `plugins: { tailwindcss: {} }` or `plugins: { '@tailwindcss/postcss': {} }`).","cause":"Attempting to use `require('tailwindcss')` directly as a PostCSS plugin in v4, or missing `@tailwindcss/postcss` package.","error":"Error: \"tailwindcss\" is not a PostCSS plugin."},{"fix":"Ensure `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.","cause":"The Tailwind CSS CLI is not installed or not accessible in your system's PATH.","error":"tailwindcss: command not found"},{"fix":"Review 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.","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.","error":"No utility classes were generated. Ensure your content config is correct."},{"fix":"Ensure 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`.","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.","error":"Unknown @import rule: \"tailwindcss\""}],"ecosystem":"npm"}