1. Global CSS
-
You can import global CSS files inside your custom
_app.js. -
Example:
-
Note: Global CSS can only be imported here, not in individual components or pages.
2. CSS Modules
-
Scoped CSS to a single component to avoid naming conflicts.
-
Filename:
Component.module.css
Example:
3. Sass / SCSS
-
Next.js supports Sass out of the box.
-
Install Sass:
-
Use
.scssor.sassfiles as global or modules.
Example with SCSS module:
4. Styled JSX (Built-in CSS-in-JS)
-
Next.js includes Styled JSX for scoped styles inside components.
Example:
5. Using CSS-in-JS Libraries
-
You can use libraries like styled-components, Emotion, or Stitches.
-
Requires additional setup for server-side rendering.
Example with styled-components:
6. Tailwind CSS
-
Utility-first CSS framework popular with Next.js.
-
Easy to configure with Next.js for rapid styling.
Setup summary:
Configure tailwind.config.js and import Tailwind styles globally.
Summary Table
| Styling Method | Description | When to Use |
|---|---|---|
| Global CSS | Site-wide styles | Base styles, resets |
| CSS Modules | Scoped CSS per component | Avoid naming collisions |
| Sass/SCSS | Extended CSS with variables, nesting | Larger projects needing structure |
| Styled JSX | Inline scoped CSS inside components | Simple component-level styles |
| CSS-in-JS (styled-components, Emotion) | JS-based styling with dynamic props | Complex styles, theming |
| Tailwind CSS | Utility-first CSS framework | Rapid UI building with utility classes |
