Menu

Sass: What is the Sass CSS Preprocessor?

6 min read Mis à jour le 05 Apr 2026

Définition

Sass (Syntactically Awesome Style Sheets) is a CSS preprocessor that extends standard CSS capabilities by adding variables, nesting, mixins, functions, and partial file imports. It compiles into standard CSS compatible with all browsers.

What is Sass?

Sass, an acronym for Syntactically Awesome Style Sheets, is a CSS preprocessor created in 2006 by Hampton Catlin and primarily developed by Natalie Weizenbaum. It extends the CSS language by adding programming features that do not exist in native CSS: variables, control structures, functions, mixins, and modules. Sass code is compiled into standard CSS before being sent to the browser, ensuring complete compatibility with all browsers.

Sass exists in two syntaxes. The original syntax, called "indented syntax" or simply "Sass" (.sass files), uses indentation rather than braces and semicolons. The second syntax, SCSS (Sassy CSS, .scss files), is more recent and more popular: it retains classic CSS syntax while adding Sass features. Any valid CSS file is automatically a valid SCSS file, which facilitates migration. At KERN-IT, our stack uses PostCSS with plugins like postcss-nested and postcss-simple-vars that offer similar capabilities to Sass nesting and variables, integrated directly into our Tailwind CSS configuration.

Why Sass Matters

CSS is a powerful language for visual presentation, but its limitations become evident on large-scale projects. Without abstraction tools, stylesheets quickly become repetitive, hard to maintain, and error-prone. Sass addresses these challenges with software engineering tools adapted to the CSS world.

  • Variables and design tokens: Sass allows defining variables for colors, sizes, spacing, and fonts, centralizing design decisions in a single place and facilitating global modifications.
  • Nesting: the ability to nest CSS selectors mirrors the HTML structure and makes code more readable while reducing repetition of parent selectors.
  • Mixins and reuse: mixins are reusable code blocks that can accept parameters, similar to functions. They eliminate code duplication for recurring visual patterns.
  • Modules and organization: the partials and import system allows splitting stylesheets into thematic files (typography, layout, components) for clean, maintainable organization.
  • Functions and calculations: Sass offers built-in functions for color, number, and string manipulation, as well as the ability to create custom functions.
  • Compatibility and transition: since SCSS is a superset of CSS, adoption can be gradual. Existing CSS files work directly as SCSS.

How It Works

The workflow with Sass involves a compilation step. The developer writes code in .scss (or .sass) files, which are then compiled into standard .css files by the Sass compiler. This compilation can be executed manually, automated via a build tool (Webpack, Vite, Gulp), or integrated into an npm script. In development mode, compilation happens in real time with a watcher that automatically recompiles on each change.

Nesting allows CSS rules to be nested to reflect the HTML hierarchy. Rather than repeating the parent selector for each child rule, the developer nests selectors. The Sass compiler "flattens" this nesting into classic CSS selectors. The ampersand character (&) references the parent selector and allows building complex selectors or variants (such as &:hover, &--modifier).

Sass variables, prefixed with the dollar sign ($), store reusable values. They differ from CSS custom properties (CSS variables) in that they are resolved at compile time, not at runtime. Mixins, defined with @mixin and used with @include, encapsulate reusable groups of declarations. Combined with parameters and default values, they offer considerable abstraction power.

Concrete Example

Imagine a development team tasked with creating a consistent design system for a large-scale web application. Without Sass, colors would be repeated hundreds of times in the stylesheet, media queries would be duplicated for each component, and any color palette modification would require a risky find-and-replace across all CSS code.

With Sass, the team defines design tokens in a centralized variables file: primary and secondary colors, typographic scales, responsive breakpoints, and spacing. Mixins encapsulate recurring patterns: a mixin for buttons that accepts color and size as parameters, a mixin for responsive media queries, a mixin for consistent box shadows. Interface components are organized in thematic partial files: _buttons.scss, _cards.scss, _forms.scss, _navigation.scss.

At KERN-IT, our approach with Tailwind CSS and PostCSS offers similar benefits with a different philosophy. Design tokens are defined in the tailwind.config.js file, utility classes replace mixins, and PostCSS plugins like postcss-nested provide nesting. Both approaches are valid, and the choice depends on the project's nature and team preferences.

Implementation

  1. Choose the syntax: opt for SCSS (recommended for most projects) which retains familiar CSS syntax, or indented Sass for teams that prefer a more concise style.
  2. Configure compilation: integrate the Sass compiler into the project's build pipeline via Webpack, Vite, or a simple npm script with node-sass or dart-sass.
  3. Organize files: structure stylesheets into partial files (prefixed with an underscore) and group them in a main file that imports them.
  4. Define design tokens: create a centralized variables file for the project's colors, typography, spacing, and breakpoints.
  5. Create reusable mixins: encapsulate recurring visual patterns in parameterized mixins to eliminate duplication.
  6. Avoid excessive nesting: limit nesting to a maximum of three levels to avoid generating overly specific CSS selectors that are difficult to override.
  7. Compile and optimize: in production, compile in compressed mode to minify CSS and use tools like PurgeCSS to eliminate unused code.

Associated Technologies and Tools

  • PostCSS: CSS transformation tool used in the KERN-IT stack, offering similar capabilities to Sass through plugins (postcss-nested, postcss-simple-vars), natively integrated with Tailwind CSS.
  • Tailwind CSS: utility-first CSS framework that represents an alternative approach to Sass. Rather than writing custom CSS, styles are applied via utility classes directly in the HTML.
  • Less: alternative CSS preprocessor to Sass, with syntax close to CSS and an ecosystem historically linked to Bootstrap.
  • CSS Modules: CSS scoping technique that limits style scope to a specific component, often used with React.
  • Styled Components: CSS-in-JS approach for React that allows writing CSS directly within JavaScript components.
  • Dart Sass: the primary and recommended Sass implementation, written in Dart, faster and more up-to-date than the legacy Node version (node-sass).

Conclusion

Sass remains a valuable tool in the frontend developer's arsenal, even as the CSS landscape has evolved considerably. Native CSS variables, nesting features being standardized, and utility frameworks like Tailwind CSS now offer viable alternatives for certain needs. Nevertheless, the power of Sass mixins, functions, and module system makes it a relevant choice for projects requiring granular control over generated CSS. Understanding Sass remains an important skill for any frontend developer, as its concepts (variables, nesting, reuse) are found in all modern approaches to CSS management.

Conseil Pro

Limit nesting to a maximum of three levels. Overly deep nesting generates ultra-specific CSS selectors that become a nightmare to maintain and override. If you exceed three levels, it is often a sign that your component structure can be simplified or that you should use utility classes instead.

Un projet en tête ?

Discutons de comment nous pouvons vous aider à concrétiser vos idées.