Using Sass in React Applications

React applications can use Sass to organize global styles, shared design tokens, and component-specific stylesheets. A typical setup installs the sass package and imports an SCSS entry point from the application's JavaScript entry point or root component.

Global styles commonly include resets, typography, theme tokens, and broad layout conventions. Component styles should generally remain focused on the component they describe.

React does not require Sass. It is a stylesheet compilation choice that works alongside the framework's component model. A project can use global SCSS, Sass modules, CSS Modules, or a combination when boundaries are clear.

Import Global SCSS into React
// src/main.jsx
import React from "react";
import { createRoot } from "react-dom/client";
import App from "./App";
import "./styles/main.scss";

createRoot(document.getElementById("root")).render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);
💡 The stylesheet import asks the configured build tool to process the SCSS file. In a typical Vite-based React project, installing sass enables SCSS imports without a separate manual compilation command. The exact entry-point filename may differ between projects. Keep global styles centralized and avoid importing the same global stylesheet redundantly across many components.
Key Takeaways
  • Install Sass as a project dependency.
  • Import global SCSS from the application's root entry point.
  • Keep global styles and component-specific styles separate.
  • React does not execute Sass; the build pipeline compiles it.
Knowledge Check

What does importing an SCSS file in a typical configured React build pipeline do?