Sass

Also known as: SCSS

On this page 7

Sass is a CSS preprocessor: a stylesheet language that extends CSS with variables, nesting, mixins, functions and modules, and then compiles into standard CSS before it reaches the browser. In CSS development, Sass lets teams write large stylesheets with less repetition and clearer structure, while browsers still receive ordinary CSS files.

Sass offers two syntaxes. The widely used SCSS syntax is a strict superset of CSS, so every valid CSS file is also valid SCSS, while the older indented syntax with the .sass extension drops braces and semicolons in favor of indentation. The reference implementation today is Dart Sass, which replaced the deprecated LibSass and Ruby Sass.

How Sass compiles to CSS

Sass works as a build-time compiler: source files with the .scss or .sass extension are read, evaluated and written out as .css files. Evaluation resolves variables, expands nested rules into full selectors, inlines mixins, runs functions and loops, and merges modules. The browser never sees Sass code, so there is no runtime cost in the page itself.

The compiler is usually invoked through the sass command-line tool or integrated into bundlers such as Vite or webpack. A typical command is sass src/main.scss dist/main.css --style=compressed, and the --watch flag recompiles on every save. Compilers also emit source maps, which let browser developer tools point to the original Sass line rather than the generated CSS.

Files whose names begin with an underscore, such as _buttons.scss, are partials. They are not compiled on their own and exist only to be loaded by other files, which keeps a project split into small, focused units.

Core Sass features

Sass adds a small set of language features that address the repetitive parts of hand-written CSS. The table below lists the most important ones and the problem each solves.

FeatureExample syntaxProblem it solves
Variables$brand: #0a66c2;Repeated literal values
Nesting.nav { a { color: $brand; } }Long repeated selectors
Mixins@mixin focus-ring { ... }Reusable groups of declarations
Functions@function rem($px) { ... }Calculated values
Modules@use 'tokens';Global namespace collisions
Control flow@each, @if, @forGenerating repetitive rules
Placeholder selectors%card with @extendSharing a rule set across selectors
Main features of Sass and their purpose

The module system built on @use and @forward is the modern way to organize Sass. Unlike the deprecated @import rule, which dumped every variable into one global scope and could load the same file many times, @use loads each file once and namespaces its members, as in tokens.$brand. Dart Sass has deprecated @import and plans its removal, so new code should always use the module system.

Sass compared with native CSS and other tools

Modern CSS has absorbed several ideas that once required Sass, so choosing Sass today depends on which features a project still needs. CSS custom properties and native CSS nesting now cover variables and basic nesting directly in the browser, but they behave differently from their Sass counterparts.

CapabilitySassNative CSS
VariablesResolved at compile time, staticCustom properties, live at runtime
NestingExpanded by the compilerSupported in current browsers
Mixins and functionsFull support with argumentsNot yet available in stable form
Loops and conditionals@each, @for, @ifNot available
Theme switching at runtimeRequires generated variantsChange a custom property
Math on unitsmath.div() and module functionscalc(), clamp(), min(), max()
Sass features versus native CSS equivalents

The key distinction is compile time versus runtime. A Sass variable disappears after compilation, so it cannot react to a media query or a user theme toggle, while a custom property can. Many teams therefore combine the two: Sass holds design tokens and generation logic, and emits CSS custom properties for anything that must change in the browser.

Sass also differs from utility-first frameworks such as Tailwind CSS, which compose styles from predefined classes in markup, and from PostCSS, which transforms standard CSS through plugins rather than offering a separate language. Less is the closest alternative preprocessor, but Sass has the larger ecosystem and more active development.

Structuring a Sass codebase

A maintainable Sass project separates tokens, tools and output so that files which only define values never emit CSS by accident. A common layout follows a layered architecture, loading general settings first and specific components last, which aligns with how the CSS cascade and specificity resolve conflicts.

LayerContentsEmits CSS
SettingsColors, spacing scale, breakpoints as variablesNo
ToolsMixins and functions such as a breakpoint mixinNo
BaseResets and element defaultsYes
ComponentsButtons, cards, navigationYes
UtilitiesSmall single-purpose helper classesYes
A typical layered Sass folder structure

A breakpoint mixin is a classic example of the tools layer. Defining @mixin above($bp) that wraps a media query lets every component write @include above(md) { ... }, so breakpoint values live in one map and change in one place. The same pattern works for container queries, focus styles and reduced-motion handling.

Common mistakes and limitations

Sass makes it easy to generate large amounts of CSS from little source code, and most problems come from that power being used carelessly. The following table lists typical issues seen in production stylesheets.

MistakeConsequenceBetter practice
Deep nestingOver-specific selectors, hard overridesLimit nesting to about three levels
Overusing @extendBloated, unpredictable selector groupsPrefer mixins or shared classes
Using @importDuplicate output, global name clashesMigrate to @use and @forward
Large loopsThousands of unused utility rulesGenerate only what the design needs
Slash for divisionDeprecation warnings, wrong outputUse math.div() from sass:math
Frequent Sass problems and how to avoid them

Beyond these mistakes, Sass adds a build step and a toolchain dependency that small projects may not need, and its static variables cannot replace runtime theming. Debugging also happens one step removed from the source, which is why source maps should stay enabled during development.

Understanding it simply

Sass is a more convenient way to write the style rules that decide how a website looks. Instead of typing the same color or size dozens of times, a designer names it once and reuses the name everywhere. Sass then translates everything into regular CSS, the only styling language browsers understand.

Think of it like writing a recipe with shortcuts, such as “use the house sauce”, and having a helper expand each shortcut into the full list of ingredients before the dish is served. The diner never sees the shortcuts, only the finished meal.

Applied in practice

A digital agency maintains a white-label booking platform used by twelve regional hotel chains, each with its own colors, fonts and corner radius. Before adopting Sass, the team kept twelve copies of a 4,000-line stylesheet, and every bug fix had to be applied to each copy by hand.

The team moves shared styles into Sass partials loaded with @use, and stores each brand as a small settings file containing a map of tokens. A single build script loops over the brands, configures the token module with @use 'tokens' with (...), and compiles one CSS file per client. Brand values that guests can toggle, such as a high-contrast mode, are emitted as CSS custom properties.

After the change, a layout fix is written once and reaches all twelve sites in the next build, and onboarding a new hotel chain means adding one settings file of about 40 lines rather than forking the entire stylesheet.