rembrembdocs

CSS

Last updated April 23, 2026

Next.js provides several ways to style your application using CSS, including:

Tailwind CSS

Tailwind CSS is a utility-first CSS framework that provides low-level utility classes to build custom designs.

Install Tailwind CSS:

pnpm

pnpm

npm

npm

yarn

yarn

bun

bun

Terminal

pnpm add -D tailwindcss @tailwindcss/postcss

Add the PostCSS plugin to your postcss.config.mjs file:

postcss.config.mjs

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

Import Tailwind in your global CSS file:

app/globals.css

@import 'tailwindcss';

Import the CSS file in your root layout:

app/layout.tsx

JavaScriptTypeScript

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

Now you can start using Tailwind's utility classes in your application:

app/page.tsx

JavaScriptTypeScript

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>
  )
}

Good to know: If you need broader browser support for very old browsers, see the Tailwind CSS v3 setup instructions.

CSS Modules

CSS Modules locally scope CSS by generating unique class names. This allows you to use the same class in different files without worrying about naming collisions.

To start using CSS Modules, create a new file with the extension .module.css and import it into any component inside the app directory:

app/blog/blog.module.css

.blog {
  padding: 24px;
}

app/blog/page.tsx

JavaScriptTypeScript

import styles from './blog.module.css'
 
export default function Page() {
  return <main className={styles.blog}></main>
}

Global CSS

You can use global CSS to apply styles across your application.

Create a app/global.css file and import it in the root layout to apply the styles to every route in your application:

app/global.css

body {
  padding: 20px 20px 60px;
  max-width: 680px;
  margin: 0 auto;
}

app/layout.tsx

JavaScriptTypeScript

// These styles apply to every route in the application
import './global.css'
 
export default function RootLayout({
  children,
}: {
  children: React.ReactNode
}) {
  return (
    <html lang="en">
      <body>{children}</body>
    </html>
  )
}

Good to know: Global styles can be imported into any layout, page, or component inside the app directory. However, since Next.js uses React's built-in support for stylesheets to integrate with Suspense, this currently does not remove stylesheets as you navigate between routes which can lead to conflicts. We recommend using global styles for truly global CSS (like Tailwind's base styles), Tailwind CSS for component styling, and CSS Modules for custom scoped CSS when needed.

External stylesheets

Stylesheets published by external packages can be imported anywhere in the app directory, including colocated components:

app/layout.tsx

JavaScriptTypeScript

import 'bootstrap/dist/css/bootstrap.css'
 
export default function RootLayout({
  children,
}: {
  children: React.ReactNode
}) {
  return (
    <html lang="en">
      <body className="container">{children}</body>
    </html>
  )
}

Good to know: In React 19, <link rel="stylesheet" href="..." /> can also be used. See the React link documentation for more information.

Ordering and Merging

Next.js optimizes CSS during production builds by automatically chunking (merging) stylesheets. The order of your CSS depends on the order you import styles in your code.

For example, base-button.module.css will be ordered before page.module.css since <BaseButton> is imported before page.module.css:

page.tsx

JavaScriptTypeScript

import { BaseButton } from './base-button'
import styles from './page.module.css'
 
export default function Page() {
  return <BaseButton className={styles.primary} />
}

base-button.tsx

JavaScriptTypeScript

import styles from './base-button.module.css'
 
export function BaseButton() {
  return <button className={styles.primary} />
}

Recommendations

To keep CSS ordering predictable:

Development vs Production

Next Steps

Learn more about the alternatives ways you can use CSS in your application.

[

Tailwind CSS v3

Style your Next.js Application using Tailwind CSS v3 for broader browser support.

](../../guides/tailwind-v3-css/index.md)[

Sass

Style your Next.js application using Sass.

](../../guides/sass/index.md)[

CSS-in-JS

Use CSS-in-JS libraries with Next.js

](../../guides/css-in-js/index.md)

Was this helpful?