by Sai gowtham

How to use sass stylesheet in react app

In this tutorial, we are going to learn about how to add and use sass(syntactically awesome style sheets) to your create react app with the help of an example.

What is Sass?

  • Sass is a css preprocessor, which allows us to use features that don’t exist in CSS like nesting, mixins, inheritance, etc.

  • Sass compiler complies your sass files into css files.

Adding sass to react

To use sass in react we need to install a new package called node-sass from the npm.

This tutorial assumes that you already created a new react project using create-react-app cli.

Run the below command to install node-sass.

npm i node-sass

Now, we are ready to use sass in our react app without ejecting.

Using sass

Now, rename your .css files into .scss and also change your css imports to scss.

Example:

index.scss
$font-stack: Helvetica, sans-serif;
$primary-color: #333;

body {
  font: 100% $font-stack;
  color: $primary-color;
}
index.js
import React from 'react';
import ReactDOM from 'react-dom';
import './index.scss';import App from './App';


ReactDOM.render(<App />, document.getElementById('root'));

Css Tutorials & Demos

How rotate an image continuously in CSS

In this demo, we are going to learn about how to rotate an image continuously using the css animations.

How to create a Instagram login Page

In this demo, i will show you how to create a instagram login page using html and css.

How to create a pulse animation in CSS

In this demo, i will show you how to create a pulse animation using css.

Creating a snowfall animation using css and JavaScript

In this demo, i will show you how to create a snow fall animation using css and JavaScript.

Top Udemy Courses

JavaScript - The Complete Guide 2022 (Beginner + Advanced)
JavaScript - The Complete Guide 2022 (Beginner + Advanced)
116,648 students enrolled
52 hours of video content
$14.99 FROM UDEMY
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
631,582 students enrolled
49 hours of video content
$24.99 FROM UDEMY
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
203,937 students enrolled
31.5 hours of video content
$14.99 FROM UDEMY