Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Next.js Tutorial
  • Next.js Components
  • Next.js Functions
  • Next.js Deployment
  • Next.js Projects
  • Next.js Routing
  • Next.js Styles
  • Next.js Server-Side Rendering
  • Next.js Environment Variables
  • Next.js Middleware
  • Next.js Typescript
  • Next.js Image Optimization
  • Next.js Data Fetching
Open In App
Next Article:
How to Import SVGs Into Your Next.js Apps?
Next article icon

How to import SASS in Next.js ?

Last Updated : 22 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Sass is the short form of Syntactically Awesome Style Sheet. It is an upgrade to Cascading Style Sheets (CSS). Sass is a CSS pre-processor. It is fully compatible with every version of CSS. Importing SASS in Next.js allows you to use SCSS for styling your application. This integration enables advanced styling features and maintains consistency across your project.

In this article, we will discuss the way to import the Sass in the Next.js Application. Below is the step-by-step implementation.

Approach

To import SASS in the next.js we will first install sass from the node package manager with npm command. After installation add .scss to the global styling file. Now to use sass in the application import use import ‘./styles.module.scss’; in the JSX file.

Steps to Implement SASS in Next.js App

Step 1: Create the Next.js application using the following command:

npx create-next-app project_test
  • project_test: Our Next.js Application Name.

Project Structure:

The following packages and dependencies will be installed automatically.

Next.js Application Directory Structure.

Now our task is to import the Sass inside our Application. Use the following steps to import Sass inside our application.

Step 2: Install the Sass Package inside the Application using the following command:

npm i sass npm add sass 

As you can see inside the styles directory Home.module.css file is there. We will use this file only and import Sass.

Step 3: Add global sass styles:

  • Go to the ‘styles’ directory and select the ‘globals.css’ file and change the extension to either ‘.sass’ or ‘.scss’.
globals.scss
  • Update the following line inside the pages->app.js file:
import styles from '../styles/globals.scss'

Step 4: Now we will test our sass installation. To do this update your index.js file with the following code.

JavaScript
// index.js  export default function Home() {     return (         <>             <h1 class="title">GeeksforGeeks</h1>             <h3>Import Sass in Next.js</h3>         </>     ) } 

Step 5: We will target <h1> element for changing the text color using the sass styling. our globals.scss file will look like this.

CSS
/* globals.scss */  $text_color: green; .title{     color: $text_color; } 

Step to run the application: To run the Next.js Application use the following command:

npm run dev

Output:



Next Article
How to Import SVGs Into Your Next.js Apps?
author
harishcarpenter
Improve
Article Tags :
  • JavaScript
  • ReactJS
  • Technical Scripter
  • Web Technologies
  • Next.js
  • SASS
  • Technical Scripter 2022

Similar Reads

  • How to import image in Next.js ?
    Next.js is a full-stack React-based framework. Unlike a traditional react app, which loads and renders the entire application on the client, Next.js allows the first-page load to be rendered by the server, which is great for SEO and performance. Some of the key features of Next.js are:  Server-side
    4 min read
  • How to Import SVGs Into Your Next.js Apps?
    Next.js is a powerful React framework that simplifies building and deploying web applications. Incorporating SVGs (Scalable Vector Graphics) into your Next.js projects can enhance your user interface with high-quality, scalable images. In this article, we will see how to Import SVGs Into Your Next.j
    5 min read
  • How to use React Icons in Next.js ?
    Icons make the website beautiful and interactive. Icons are an important part of a website's user interfaces, which are used in expressing objects, actions, and ideas. They are used to communicate the core idea and intent of a product or action and express the object visually. Here, we will learn to
    3 min read
  • How to Import SAS Files into R?
    In this article, we are going to see how to import SAS files(.sas7bdat) into R Programming Language.  SAS stands for Statistical Analysis Software, it contains SAS program code saved in a propriety binary format. The R packages discussed, haven and sas7bdat, involved reverse engineering this proprie
    1 min read
  • How to ignore ESLint in Next.js ?
    In this article, we are going to see how to ignore ESLint in Next.Js. Follow the below steps to ignore ESLint in the Next.js application: ESLint: ESLint is a JavaScript linter that is designed to help identify and correct problems in JavaScript code. ESLint is based on JSHint, but ESLint has more fe
    2 min read
  • How to import SASS through npm ?
    Introduction to SASS: SASS stands for 'Syntactically awesome style sheets'. It is an extension of CSS, that makes it easy to use variables of CSS, nested rules, inline import, and many other important features SASS has two syntax options: SCSS (Sassy CSS): It uses the .scss file extension and is ful
    3 min read
  • How to add Web Share in Next.js ?
    The Web Share API enables web applications to share content (like URLs, text, or files) to other apps installed on a user's device, such as social media platforms, messaging apps, or email clients. Integrating the Web Share API into a Next.js project enhances user experience by providing a seamless
    2 min read
  • How to add Slider in Next.js ?
    Adding a slider in Next.js involves integrating a slider component, like react-range, managing its state using React hooks and applying styles for customization, enhancing user interaction and input precision in your application. ApproachTo add our Slider we are going to use the react-range package.
    2 min read
  • How to add Testimonials in Next.js ?
    In this article, we are going to learn how we can add the Testimonials in NextJs. NextJS is a React-based framework. It has the power to Develop beautiful Web applications for different platforms like Windows, Linux, and mac. The linking of dynamic paths helps in rendering your NextJS components con
    2 min read
  • How to Add Stylesheet in Next.js ?
    In Next.js, adding a stylesheet enhances your app's styling capabilities. Import CSS files directly in your components or pages using ES6 import syntax. Next.js optimizes and includes these styles in the build process, ensuring efficient and modular CSS management. In this post, we are going to lear
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences