Tailwind CSS in Next.js

Beginner · 4 min

Install Tailwind CSS v4 in a Next.js 16 app with the PostCSS plugin, import it once in your root layout, and know where it fits next to CSS Modules.

Before thisCSS Modules and global CSS

KodeBase · 4 min

Tailwind CSS in Next.js

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by KodeBaseReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • Tailwind in Next.js is two packages (`tailwindcss` and `@tailwindcss/postcss`), a one-line PostCSS config, and one `@import 'tailwindcss'` in a global stylesheet.
  • You import that stylesheet once, in the root layout; after that, utility classes work in any Server or Client Component.
  • Tailwind's class names are plain strings in `className`, so they need no `"use client"` and no runtime.
  • The docs recommend Tailwind for most styling and CSS Modules for what utilities do not cover; the two can live in the same project.
  • Tailwind v3 setup is a separate guide, meant for projects that need broader support for very old browsers.

Why a framework, not a stylesheet

Tailwind is a utility-first CSS framework: instead of naming a class and writing rules for it, you compose small single-purpose classes straight in your markup. flex, p-24, and text-4xl each do one thing. The reasoning behind that style, and its costs, are in the css roadmap’s utility-first CSS and Tailwind. This lesson is only the Next.js side: getting it installed and knowing how it sits with the rest of your styling.

The App Router is a good fit. A class name is a string, and strings pass through Server Components untouched, so you get styling with zero client JavaScript.

Install

The current docs install two packages as dev dependencies:

npm install -D tailwindcss @tailwindcss/postcss

Tailwind’s work happens in PostCSS, which Next.js runs on your CSS. So you register a plugin in postcss.config.mjs at the project root:

// postcss.config.mjs
export default {
  plugins: {
    '@tailwindcss/postcss': {},
  },
}

Then put one line in your global CSS:

/* app/globals.css */
@import 'tailwindcss';

And import that file in the root layout:

// app/layout.tsx
import './globals.css'

export default function RootLayout({
  children,
}: {
  children: React.ReactNode
}) {
  return (
    <html lang="en">
      <body>{children}</body>
    </html>
  )
}

The @import line is what pulls Tailwind’s generated styles in. Note what is missing: the setup in the Next.js docs has no tailwind.config.js and no list of files to scan. For where a new project’s files come from, see creating a Next.js project.

Use it

// app/page.tsx
export default function Page() {
  return (
    <main className="flex min-h-screen flex-col items-center justify-between p-24">
      <h1 className="text-4xl font-bold">Welcome to Next.js!</h1>
    </main>
  )
}

That is a Server Component with no directive, styled entirely by classes. If a component becomes interactive later and needs "use client", its classes keep working unchanged.

Where it sits with the rest of your CSS

The Next.js CSS docs lay out a clear ordering. Use Tailwind for most styling because it covers common design patterns. Use CSS Modules for component-specific styles when utilities are not enough. Keep plain global CSS for truly global rules like Tailwind’s own base styles. Import the Tailwind stylesheet in the root of the app so CSS ordering stays predictable.

Fonts connect to Tailwind through CSS variables, which the next lesson shows with @theme inline.

An older setup

Tailwind v4 is what the docs install now. If you need broader support for very old browsers, they point to a separate Tailwind v3 setup guide instead. For a new project that targets current browsers, you do not need it. For an existing project, check which major version you have before you copy a snippet from a tutorial — the two are set up differently, so a v3 snippet pasted into a v4 project will not match the steps above.

What the video covers

KodeBase’s video, from February 2026, is titled “How to Install Tailwind CSS in Next JS v16” and runs under four minutes. By its title it is an install walkthrough on Next.js 16, and that is all this lesson claims: it has no chapters and we could not read a transcript. It is the freshest fit we found. It comes from a small channel and covers install only, so the usage guidance above comes from the docs. The runner-up, from Md Al Mamun, is a longer setup on Next.js 15 with Tailwind v4 that includes a short sponsor segment.

Where this fits

Styling gets you the look; text needs the right typeface too. Next: fonts with next/font.

Check yourself

  1. 01What are the three pieces of a Tailwind v4 setup in a Next.js project?

    Install `tailwindcss` and `@tailwindcss/postcss`, register `@tailwindcss/postcss` as a plugin in `postcss.config.mjs`, and add `@import 'tailwindcss';` to a global CSS file that the root layout imports.

  2. 02Where should the global stylesheet containing `@import 'tailwindcss'` be imported, and why there?

    In the root layout, so the styles are loaded for every route. The CSS docs also say to import Tailwind stylesheets in the root of the app to keep CSS ordering predictable.

  3. 03Do you need `"use client"` to use Tailwind classes?

    No. Utility classes are strings passed to `className`, which works in Server Components. Only the interactive parts of your UI need `"use client"`, for reasons that have nothing to do with styling.

  4. 04When would you write a CSS Module in a Tailwind project?

    For component-specific styles that utilities do not cover well. The docs recommend Tailwind for most styling and CSS Modules for that remainder.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark