skip to content

Sass

Dart Sass compiles SCSS through @use and @forward modules, mixins, functions and @extend, with @import now deprecated. Interviewers ask what Sass still earns over modern CSS.

on this pageshow

explore

questions

6

What is Sass, how do its SCSS and indented syntaxes differ, and what does the browser actually receive from a .scss file?

level: juniorimportance: must knowfreq 28%

answer

  1. a language compiled before the browser
  2. two syntaxes, one feature set
  3. braces versus indentation
  4. only plain CSS ships
  5. Dart Sass: sass or sass-embedded

basics

~20 s

Sass is a stylesheet language compiled to plain CSS at build time by Dart Sass. SCSS (.scss) is nearly a superset of CSS; the indented syntax (.sass) swaps braces and semicolons for indentation. The browser only receives the compiled CSS.

solid answer

~40 s

Sass adds variables, nesting, mixins, functions, `@extend`, control flow such as `@each` and `@if`, and a module system (`@use`, `@forward`) on top of CSS. None of it runs in the browser: the compiler substitutes every variable, expands every mixin, flattens nested rules and drops placeholder selectors, so the output is an ordinary `.css` file. Both syntaxes have the same features: **SCSS** (`.scss`), where essentially all valid CSS is valid SCSS, and the original **indented syntax** (`.sass`), which uses indentation instead of braces and semicolons; each can load the other. The maintained implementation is Dart Sass, on npm as `sass` (compiled to pure JavaScript) and `sass-embedded` (a wrapper around the native Dart compiler, released at the same version and generally faster on large stylesheets). LibSass and `node-sass` are end-of-life.

code

scss · 17 lines
scss
// history-site/main.scss
@use "campus-ui/tokens";

$card-gap: 1.5rem;

@mixin elevated {
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

.event-card {
  padding: $card-gap;
  @include elevated;

  &__title {
    color: tokens.$brand-navy;
  }
}

go deeper

for a junior

Say plainly that Sass is compiled ahead of time and only CSS ships. Name the two syntaxes by file extension and one feature Sass adds, such as variables or mixins.

for a middle

Explain what the compiler does to each feature: variables substituted, mixins expanded, nesting flattened, placeholders dropped, and unknown functions passed through as plain CSS.

for a senior

Show you know the toolchain: Dart Sass is the only maintained implementation, sass versus sass-embedded is a build-speed choice, and a LibSass-era project needs a migration, not a version bump.

for a principal

Treat Sass as a build-time dependency with its own deprecation policy, and weigh what it still adds over modern CSS against keeping a preprocessor in every pipeline.

## What Sass is **Sass** is a stylesheet language layered on top of CSS. You write `.scss` (or `.sass`) files, a **compiler** turns them into ordinary `.css` during the build, and the browser only ever sees that output. In a normal build nothing about Sass runs at page load: there is no Sass runtime, no interpretation in the browser and no Sass-specific syntax left in the delivered file. What Sass adds is a set of authoring features, every one of them resolved at compile time: - **Variables** (`$brand-navy: #1d3a5f;`) whose values are substituted wherever they are referenced. - **Nesting**, including the parent selector `&`, which the compiler flattens into ordinary selectors: `&__title` written inside `.event-card` becomes `.event-card__title`. - **Mixins** (`@mixin` / `@include`) that paste reusable declarations and rules where they are included. - **Functions** (`@function` / `@return`) and built-in modules such as `sass:math` and `sass:color` that compute values. - **`@extend` and placeholder selectors** (`%name`) that let one selector share another's rules. - **Control flow** (`@if`, `@each`, `@for`, `@while`) for generating rules from data. - A **module system** (`@use` and `@forward`) for splitting code across files behind namespaces. ## What the compiler does with each feature | Feature in the source | What reaches the CSS output | |---|---| | `$variable` | Its value, substituted at each use | | Nested rule with `&` | A flat selector such as `.event-card__title` | | `@include` of a mixin | The mixin's declarations and rules, copied in | | Call to a Sass function | The computed value | | `%placeholder` | Nothing on its own; only the selectors that extend it | | `@each` / `@if` | Whatever rules the loop or branch generated | | A function Sass does not know | The call, passed through unchanged as plain CSS | The last row matters in practice. Any call that is neither a user-defined nor a built-in Sass function is compiled as a plain CSS function with its arguments compiled as-is, so new CSS functions work without waiting for a Sass release. The same design means a misspelt helper name is not a compile error: it is copied into the CSS. ## SCSS and the indented syntax Sass has **two syntaxes with the same features**: 1. **SCSS** (`.scss`) uses braces and semicolons. With a few small exceptions it is a superset of CSS, so essentially any valid CSS file is already valid SCSS. It is the most popular syntax and the one most teams mean when they say "Sass". 2. **The indented syntax** (`.sass`) is the original one. Indentation replaces braces, and a line end counts as a statement end. It has a few extra shorthands, such as `=` to define a mixin and `+` to include one, but no feature SCSS lacks. Each syntax can load the other, so a project can mix them, although most codebases standardise on one. Files whose names start with an underscore (`_tokens.scss`) are **partials**: they exist to be loaded by other stylesheets, and Sass tools do not compile them on their own. Only entry points produce `.css` files. ## Which compiler: Dart Sass The maintained implementation is **Dart Sass**. It ships as a standalone executable, through Homebrew and Chocolatey, and on npm as two packages that are always released at the same version: - **`sass`** is Dart Sass compiled to pure JavaScript. It runs anywhere Node.js runs (it can even run in a browser), and provides the `sass` command and a JavaScript API (`compile`, `compileAsync`, `compileString`). - **`sass-embedded`** is a JavaScript wrapper that drives the native Dart Sass compiler over the embedded protocol. It supports the same JavaScript API and language features and is generally much faster on substantial stylesheets, which is the usual reason to choose it. Two older names are history, and a candidate should recognise them as such: - **LibSass**, the C++ implementation, was deprecated in October 2020 and declared end-of-life on 2025-10-22. It never gained the module system. - **`node-sass`**, the Node.js wrapper around LibSass, was declared end-of-life in July 2024; its npm package is marked deprecated and its repository archived. A project still on it needs a migration to Dart Sass, followed by a check for output differences. ## A typical compile From the command line the one-to-one form is `sass <input.scss> <output.css>`; build tools call the same compiler through its JavaScript API. Either way the result is a CSS file, optionally with a source map that points browser devtools back to the `.scss` lines. ## Misconceptions worth correcting - "The browser reads `.scss`." It never does; only compiled CSS ships. - "The indented syntax is a cut-down Sass." It has the same features as SCSS. - "Any Sass compiler will do." Only Dart Sass is maintained; LibSass-based tools and Ruby Sass are end-of-life. - "Unknown functions are compile errors." They pass through as plain CSS calls. - "Placeholders and mixins appear in the output." They are consumed by the compiler.

  • What happens when an .scss file calls a CSS function that Sass itself does not define?
    Sass passes it through. Any call that is neither a user-defined nor a built-in Sass function is compiled as a plain CSS function, with its arguments compiled and included as-is, so new CSS functions keep working without a Sass release. The flip side is that a misspelt helper name is also copied into the CSS instead of failing the build.
  • Why would a team choose `sass-embedded` over `sass` from npm?
    Both are Dart Sass at the same version with the same language features and JavaScript API. `sass` is Dart Sass compiled to pure JavaScript, so it runs anywhere Node.js runs. `sass-embedded` drives the native Dart compiler over the embedded protocol and is generally much faster on substantial stylesheets, which is the reason to switch for a large codebase or a slow build.
  • Where do LibSass and node-sass fit today?
    They are history. LibSass, the C++ implementation, was deprecated in October 2020 and declared end-of-life on 2025-10-22, and it never supported the module system. `node-sass`, its Node.js wrapper, was declared end-of-life in July 2024 and its npm package is deprecated. Dart Sass replaces both.

  • The browser downloads the .scss file and a Sass runtime interprets it.
  • The indented .sass syntax lacks features that SCSS has.
  • node-sass is still the standard way to compile Sass in a Node project.
  • Plain CSS must be rewritten before it can be saved as .scss.
  • Mixins and placeholder selectors appear in the output CSS as written.
open as a page

With Dart Sass's module system, how does @use differ from the deprecated @import in how members are named, loaded and kept private?

level: middleimportance: must knowfreq 18%

basics

~20 s

@use loads a file once per compilation as a module whose members are namespaced (tokens.$navy), visible only to the loading file, and private when named with - or _. @import shared one global scope; Dart Sass 1.80.0 deprecated it.

open as a page

In Sass, when do you write a @mixin with @content rather than a @function, and what can each one produce?

level: middleimportance: should knowfreq 13%

basics

~20 s

A @function computes a value and hands it back with @return; it cannot emit declarations or rules. A @mixin, pulled in with @include, emits styles, and @content lets the caller pass a block the mixin wraps, such as a media query.

open as a page

In Dart Sass, why does `@use "campus-ui/tokens" with ($radius: 2px)` fail when another file loaded that module first, and how do you fix it?

level: seniorimportance: should knowfreq 8%

basics

~20 s

A module is loaded once per compilation and keeps the configuration of its first load, so @use ... with() works only on that first load. Configure the library at the top of the entry point, before anything else loads it.

open as a page

In Sass, what CSS do a %placeholder with @extend and a mixin each emit for shared styles, and why can't @extend reach across @media?

level: seniorimportance: should knowfreq 10%

basics

~20 s

A mixin copies its declarations into every rule that includes it. @extend adds the extending selector to the existing rules, so a %placeholder yields one grouped rule. Inside @media, @extend can only reach selectors in that same media context.

open as a page

A shared Sass library built on @import and global functions floods consumer builds with Dart Sass deprecation warnings; how do you migrate it to the module system safely?

level: seniorimportance: nice to knowfreq 6%

basics

~20 s

Run sass-migrator module --migrate-deps on the entry point to turn @import into @use/@forward and global functions into sass: module calls, forward the public API from the index, keep an import-only file for old consumers, and gate CI on deprecations.

open as a page