Tailwind CSS
Tailwind CSS is a utility-first CSS framework that works exceptionally well with Next.js.
Installing Tailwind
Install the Tailwind CSS packages and run the init
command to generate both the tailwind.config.js
and postcss.config.js
files:
Configuring Tailwind
Inside tailwind.config.js
, add paths to the files that will use Tailwind CSS class names:
You do not need to modify postcss.config.js
.
Importing Styles
Add the Tailwind CSS directives that Tailwind will use to inject its generated styles to a Global Stylesheet in your application, for example:
Inside the root layout (app/layout.tsx
), import the globals.css
stylesheet to apply the styles to every route in your application.
Using Classes
After installing Tailwind CSS and adding the global styles, you can use Tailwind's utility classes in your application.
Usage with Turbopack
As of Next.js 13.1, Tailwind CSS and PostCSS are supported with Turbopack.