How to Import .scss Files Anywhere in Next.js App?

Implement three SCSS scopes in Next.js globals, modules, shared variables and streamline repetitive imports with sass‑resources‑loader or modern @use/@forward syntax for maintainability.

Summarize with AI

Not enough time? get the key points instantly.

Prerequisites

  • Next.js 12+

Sass installed:

npm install sass

Scope 1: Setup Global SCSS

📁 File Structure

/styles  └── globals.scss

  └── variables.scss

🔗 Import in _app.tsx

// pages/_app.tsximport ‘../styles/globals.scss’;

 

export default function App({ Component, pageProps }) {

  return ;

}

✅ Best For: Reset styles, typography, body-level defaults.

Scope 2: Use SCSS Modules Per Component

🎯 Why Use This?

Avoid style leakage, keep styles local to components.

🛠 Example

/components/  └── Button.module.scss

 

// components/Button.tsximport styles from ‘./Button.module.scss’;

 

export default function Button() {

  return ;

}

✅ Best For: Encapsulated, reusable components.

🧩 Scope 3: Share Variables & Mixins Across Files

🛠 Example

// styles/_variables.scss$primary-color: #0070f3;

🛠 Use Anywhere

// styles/globals.scss or Button.module.scss@import ‘./variables’;

 

.button {

  color: $primary-color;

}

🚨 Important: @import is deprecated in Sass. Migrate to @use or @forward for modern workflows.

Also Read:

🚀 Optional: Auto-Import SCSS Variables Everywhere

You can avoid manually importing _variables.scss in every file.

✅ With sass-resources-loader (needs Webpack override):

1. Install dependencies:

npm install sass-resources-loader

2. Customize Webpack:

// next.config.jsconst path = require(‘path’);

 

module.exports = {

  webpack(config) {

    config.module.rules.push({

      test: /\.scss$/,

      use: [

        {

          loader: ‘sass-resources-loader’,

          options: {

            resources: path.resolve(__dirname, ‘styles/variables.scss’),

          },

        },

      ],

    });

    return config;

  },

};

✅ Tips

  • Use globals.scss for app-wide layout or reset.
  • Use .module.scss for isolated styling.
  • Extract variables/mixins into shared SCSS files and import where needed.
  • For larger teams, automate variable imports using sass-resources-loader or adopt @use/@forward syntax.

Resources

Insights from our engineering leaders.

Our team shares practical insights on the technologies and engineering decisions shaping enterprise software today, grounded in real client work.

ReactJS

Filter Items Based On Multiple Properties

Why am I getting this problem? If you apply separate filters in sequence or only check one property at a time your code will match…