Global CSS and CSS Modules
Scope: Next.js 16.x candidate, App Router, Cache Components disabled, TypeScript. Source walkthroughs and expected outcomes; no framework build or browser execution has been verified.
What you will learn
- Choose global versus local styles
- Avoid class conflicts
app/layout.tsx — partial imports and layout
import type { ReactNode } from 'react';import Link from 'next/link';import './globals.css';export default function RootLayout({ children }: { children: ReactNode }) { return <html lang="en"><body> <a className="skip" href="#main">Skip to content</a> <header><nav aria-label="Main navigation"> <Link href="/">River Books</Link><Link href="/catalog">Catalog</Link> <Link href="/help">Help</Link> </nav></header> <main id="main" tabIndex={-1}>{children}</main> </body></html>;}The global stylesheet applies to the shared header and page content on every descendant route.
How it works
CSS is still evaluated by the browser. Next.js processes imported stylesheets as part of the application build. A .module.css import provides an object whose properties refer to generated class names; selectors such as element selectors are not automatically isolated in every situation. Keep global rules small, avoid depending on a generated class name, and use deliberate specificity. This root-layout import is for App Router. In Pages Router, application-wide global stylesheet imports belong in pages/_app; do not copy the App Router file arrangement there. Tailwind is an alternative utility-class workflow with separate setup; it is not required for this app.
app/catalog/catalog.module.css and BookCard.tsx — paired snippets
.card { padding: 1rem; border: 1px solid #66717e; }/* In BookCard.tsx: import styles from "./catalog.module.css"; */Use className={styles.card} on the article in the component. The matching rule gives the card padding and a border without requiring every other card on the site to use the same style.
Common mistake
Writing className="card" after importing a module normally does not match the generated local class. Use the imported property. Global styles can persist across navigation, so do not import broad page-specific overrides merely to style one card.
Try it yourself
Create a .badge class in two separate modules with different colors. Render each with its own import and predict the result. Inspect the generated class names only after running the approved fixture.
Further reading
Next lesson: Public assets and local fonts.