Categories
React Answers

How to add SCSS styles to a React project?

Spread the love

Sometimes, we want to add SCSS styles to a React project.

In this article, we’ll look at how to add SCSS styles to a React project.

How to add SCSS styles to a React project?

To add SCSS styles to a React project, we can install the sass package if the React project is created with create-react-app.

To install it, we run:

npm install --save-dev sass

or

yarn add -D sass

Then we import a SCSS file by writing:

import '../scss/styles.scss';

We can rename all *.css files to *.scss to convert CSS files to SCSS files.

Conclusion

To add SCSS styles to a React project, we can install the sass package if the React project is created with create-react-app.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

2 replies on “How to add SCSS styles to a React project?”

How would you import SASS partials into components?
This method isn’t applicable. Partials aren’t visible when importing and an error occurs:
Cannot find module ‘../scss/components/_search-form’

Leave a Reply

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