Installation
1
Install Tailwind CSS and the PostCSS plugin
- npm
- pnpm
- yarn
- bun
2
Add the PostCSS plugin
Create or update
postcss.config.mjs at the project root:postcss.config.mjs
3
Import Tailwind in your global CSS file
app/globals.css
4
Import the CSS file in your root layout
Usage
Once configured, use Tailwind utility classes directly on any element:Using with CSS Modules
Tailwind and CSS Modules can be used together. Tailwind’s@apply directive lets you compose utilities into a module class:
app/button/button.module.css
app/button/Button.tsx
Dark mode
Tailwind’s dark mode works with Next.js. Add thedark variant to your classes:
app/page.tsx
app/globals.css
If you need support for very old browsers, see the Tailwind CSS v3 setup guide. The
@tailwindcss/postcss plugin targets modern browsers by default.