Thursday, September 4, 2025
HomeLanguagesJavascriptHow to install node-sass to React project?

How to install node-sass to React project?

Sass is a scripting language that is compiled into Cascading Style Sheets (CSS). It is a kind of preprocessor language. It was initially designed by Hampton Catlin and then it was developed by Natalie Weizenbaum. After its initial versions, Weizenbaum and Chris Eppstein have continued to extend SASS with SassScript. It supports four data types, and they are Numbers, Strings, Colors, and booleans. Nesting also works in this language.

Prerequisite:

Installation process:

  • Adding sass using npm:

    npm install node-sass --save
  • Adding sass using yarn:

    yarn add node-sass

Note: Now you can rename App.css to App.scss and update App.js to import App.scss. This file and any other file will be automatically compiled if imported with the extension .scss or .sass.
 

Example: Once you follow the above steps then it means that you had successfully installed sass and you can start using it.

  • App.sass: As you can observe in the code of sass file, we can use variables and also perform arithmetic operations in sass files. This is the advantage of using sass.

    HTML




    $bg:rgb(88, 235, 88);
    $border-color : black;
      
        
    .main-block{
      
      background-color: $bg;
      height: 4px / 100px  * 100% ;
      border: 1px solid $border-color;
      text-align: center;
      
    }

    
    
  • App.js

    Javascript




    import logo from './logo.svg';
    import './App.scss';
      
    function App() {
      return (
        <div className="App">
          <header className="App-header">
            <img src={logo} className="App-logo" alt="logo" />
              
    <p>
              Edit <code>src/App.js</code> and save to reload.
            </p>
      
            <a
              className="App-link"
              href="https://reactjs.org"
              target="_blank"
              rel="noopener noreferrer"
            >
              Learn React
            </a>
          </header>
        </div>
      );
    }
      
    export default App;

    
    
  • Output:

RELATED ARTICLES

Most Popular

Dominic
32261 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6626 POSTS0 COMMENTS
Nicole Veronica
11795 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11855 POSTS0 COMMENTS
Shaida Kate Naidoo
6747 POSTS0 COMMENTS
Ted Musemwa
7023 POSTS0 COMMENTS
Thapelo Manthata
6695 POSTS0 COMMENTS
Umr Jansen
6714 POSTS0 COMMENTS