How does Next.js handle CSS imports?
Next.js supports global CSS, CSS Modules, Tailwind CSS, Sass and CSS-in-JS out of the box. In the App Router, global CSS can be imported in any layout or component; in the Pages Router it can only be imported in _app.
Global CSS
- App Router: import
globals.cssin the rootapp/layout.tsx. Global styles imported in nested layouts or components also work, but they are global and stay on the page once loaded. - Pages Router: global CSS is allowed only in
pages/_app.tsxto avoid order conflicts.
CSS Modules
Files named *.module.css are locally scoped. Class names become unique hashes, so .button in two files never collides. In Next.js 16.4 production builds, the generated class names are shorter.
Tailwind CSS
create-next-app sets up Tailwind CSS v4 by default. It needs only @import "tailwindcss"; in globals.css and the @tailwindcss/postcss plugin in postcss.config.mjs. Theme customization lives in CSS with @theme.
Sass
Install sass and import .scss or .module.scss files. Turbopack does not support the legacy ~ prefix for node_modules imports.
How CSS is delivered
- In production CSS is extracted into
.cssfiles, minified and chunked per route, and loaded with<link>tags. - In development styles hot-reload without losing state.
- Order follows import order, so import global CSS first.
experimental.inlineCsscan inline CSS into the HTML<head>to save a request on first load.- External stylesheets from packages can be imported anywhere in the App Router.
Code example
1// app/layout.tsx2import "./globals.css"; // global styles + Tailwind34export default function RootLayout({ children }: { children: React.ReactNode }) {5 return (6 <html lang="en">7 <body>{children}</body>8 </html>9 );10}1112/* app/globals.css (Tailwind CSS v4) */13// @import "tailwindcss";14// @theme { --color-brand: #4f46e5; }1516// app/components/card.tsx - CSS Module, locally scoped17import styles from "./card.module.css"; // .card { padding: 1rem } -> .card_x7a21819export function Card({ title }: { title: string }) {20 return (21 <div className={`${styles.card} rounded-lg bg-brand text-white`}>22 {title}23 </div>24 );25}
Practice this question
Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the Next.js set.