Installation
Setting up Tailwind CSS in a Next.js project.
Start by creating a new Next.js project if you don't have one set up already. The most common approach is to use Create Next App.
npx create-next-app@latest my-project --typescript --eslint --appcd my-projectInstall @tailwindcss/webpack via npm.
npm install tailwindcss @tailwindcss/webpackAdd the @tailwindcss/webpack loader to your next.config.mjs file.
/** @type {import('next').NextConfig} */const nextConfig = { webpack(config) { config.module.rules.push({ test: /\.css$/i, use: ['@tailwindcss/webpack'], }) return config },}export default nextConfigAdd an @import to ./app/globals.css that imports Tailwind CSS.
@import "tailwindcss";Run your build process with npm run dev.
npm run devStart using Tailwind's utility classes to style your content.
export default function Home() { return ( <h1 className="text-3xl font-bold underline"> Hello world! </h1> )}