How do you use Sass in Next.js?

Install the sass package and import .scss or .sass files directly: global stylesheets in the root layout, and .module.scss files in components for scoped styles. Configure shared variables or options with sassOptions in next.config.ts.

Setup

  1. npm install --save-dev sass
  2. Global: import "./globals.scss" in app/layout.tsx.
  3. Scoped: import styles from "./button.module.scss".

sassOptions

  • additionalData: '@use "@/styles/tokens" as *;' to inject variables or mixins into every file.
  • includePaths or loadPaths for import resolution.
  • implementation: "sass-embedded" to use the faster embedded compiler.
  • silenceDeprecations to quiet known warnings during migration.

Modern Sass

  • Use @use and @forward instead of the deprecated @import.
  • Next.js 16 upgraded to sass-loader v16 with the modern Sass API.
  • Turbopack does not support the ~ prefix for node_modules imports. Write @use "bootstrap/scss/bootstrap" instead of ~bootstrap/..., or add a turbopack.resolveAlias.

Exporting variables to JavaScript

CSS Modules support :export { primary: $primary; }, so you can import Sass values in TypeScript.

Sass vs native CSS

Native CSS now has nesting, custom properties, color-mix() and container queries. Many teams use plain CSS (or Tailwind) for new projects, and keep Sass for existing design systems.

Code example

tsx
1// next.config.ts
2import type { NextConfig } from "next";
3
4const nextConfig: NextConfig = {
5 sassOptions: {
6 additionalData: `@use "@/styles/tokens" as *;`, // tokens available everywhere
7 implementation: "sass-embedded",
8 },
9};
10export default nextConfig;
11
12/* styles/_tokens.scss */
13// $brand: #4f46e5;
14// @mixin card { border-radius: 12px; padding: 1rem; }
15
16/* app/components/card.module.scss */
17// .card {
18// @include card;
19// border: 1px solid rgba($brand, 0.2);
20// &:hover { border-color: $brand; }
21// }
22// :export { brand: $brand; }
23
24// app/components/card.tsx
25import styles from "./card.module.scss";
26export function Card({ children }: { children: React.ReactNode }) {
27 return <div className={styles.card} data-brand={styles.brand}>{children}</div>;
28}

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.

Open in study app