How to add sass or scss in React

Today we’ll show you how to add sass or scss in React application. If you are using the create-react-app package in your react project then it is very easy to add sass or scss in the react app with three simple steps.

In this short article, we’ll use the npm package to configure sass/scss in the React application.

Steps to add sass or scss in React

  1. Create a react app
  2. Install sass package
  3. Create and import .scss file
  4. Output

1. Create a react app

Let’s create a simple react application using the create-react-app package. Run the following command to create a react app.

2. Install sass package

We have to install the node-sass package to use the .sass or .scss file in the react application. Run the following command to install the sass package.

Note: If you are getting an error like Error: Node Sass version 5.0.0 is incompatible with ^4.0.0. then install the [email protected] version. Run the following command to install the specific version.
npm i [email protected]

3. Create and import .scss file

After successful installation, we can create .scss or .sass file for component styling. Same as the .css file, we have to import it in the react component.

For the demonstration, let’s add the App.scss file in the App.js component to create an image card. Look at the following code.

App.scss

App.js

Output

Run the react application and check the image card output in the browser.

Output - How to add sass or scss in React - Clue Mediator
Output – How to add sass or scss in React – Clue Mediator

That’s it for today.
Thank you for reading. Happy Coding..!! 🙂

Demo & Source Code

Github Repository StackBlitz Project
If you found value in this article,
you can support us by buying me a coffee! ☕

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *