CSS preprocessor · CSS foundations recommended

Learn Sass / SCSS step by step

Learn Sass and SCSS step by step: store design values, reuse style patterns, split code into modules, and compile your work into browser-ready CSS. Every module explains the idea in plain language, walks through a code example and gives you a small task to try yourself.

Version snapshot: Dart Sass 1.105.2 · SCSS syntax. Current Dart Sass release shown by the official CLI documentation when checked on 21 October 2026. SCSS is Sass syntax; compile it to standard CSS for browsers.

Before you begin

Learn CSS selectors, the box model and responsive rules first. SCSS extends CSS authoring; it does not replace understanding CSS.

What you’ll be able to do

Structure a small design system with reusable Sass modules and produce readable, browser-ready CSS.

Work through the modules in order if you’re new to Sass / SCSS. If you already know the basics, use the contents list to jump to a topic. Try each example by changing one value, running it again and explaining the result in your own words.

Sass / SCSS terms in simple language

Sass
A stylesheet language that adds authoring features and compiles into CSS for the browser.
SCSS
The CSS-like syntax for Sass; most ordinary CSS rules can be used in an SCSS file.
Mixin
A reusable block of style rules that can accept options and be included in other rules.
Module
A Sass file that shares selected styles or values with another file using @use or @forward.
Sass variable
A named value used while compiling styles, such as a brand color or spacing size.
Sass function
A reusable calculation that returns a value for use in a style rule.
Sass map
A named collection of related settings, like all the colors in a theme.
Compile
Convert SCSS source code into CSS that a web browser can understand.
Source map
A development file that helps browser tools connect generated CSS back to its SCSS source.
In this guide · 9 modules
  1. Key terms in simple language
  2. What Sass and SCSS are
  3. Variables and useful values
  4. Nesting and the parent selector
  5. Partials and the modern module system
  6. Mixins for reusable declaration patterns
  7. Functions, maps and token lookup
  8. Loops and generated utilities
  9. Responsive components and CSS custom properties
  10. Compile, debug and ship maintainable SCSS
  11. Final project
  12. Official references
MODULE 01 / 9 · CONCEPT EXPLAINED

What Sass and SCSS are

Sass adds features that help you organize stylesheets, then compiles them into regular CSS. SCSS is the Sass syntax that looks most like the CSS you already know, so ordinary CSS rules can usually go straight into an .scss file. Browsers do not read SCSS directly; a compiler such as Dart Sass turns it into a .css file the browser can load. Think of SCSS as the source recipe and CSS as the finished dish.

Follow this example
$brand: #245f4a;

.button {
  background: $brand;
  color: white;
}
Try it yourself: Install Dart Sass in a project, create styles.scss and compile it into styles.css.
MODULE 02 / 9 · CONCEPT EXPLAINED

Variables and useful values

Sass variables store compile-time values and are useful for values you configure before building CSS. CSS custom properties remain available in the browser and can change at runtime. Use the right tool for the job: a Sass map for build-time token sets, a custom property for runtime theming.

Follow this example
$space: 1rem;
$brand: #245f4a;

:root { --brand: #{$brand}; }
.card { padding: $space; color: var(--brand); }
Try it yourself: Create spacing and color variables, compile the file and inspect the resulting CSS.
MODULE 03 / 9 · CONCEPT EXPLAINED

Nesting and the parent selector

Nesting places related rules together, and & refers to the current parent selector for states or modifiers. Keep nesting shallow: deeply nested rules generate long selectors that are harder to override. Nest related selectors only when it improves readability.

Follow this example
.button {
  padding: 0.75rem 1rem;
  &:hover { filter: brightness(0.95); }
  &--quiet { background: transparent; }
}
Try it yourself: Convert a small button component to SCSS and keep the generated selectors short.
MODULE 04 / 9 · CONCEPT EXPLAINED

Partials and the modern module system

Split large stylesheets into small files named with a leading underscore; these partials are not emitted as standalone CSS. Load and share public Sass APIs with @use and @forward. The older Sass @import rule is deprecated; move code toward modules instead of starting new projects with imports.

Follow this example
// _tokens.scss
$brand: #245f4a;

// styles.scss
@use 'tokens';
.page-title { color: tokens.$brand; }
Try it yourself: Move tokens to a partial and access them through its namespace using @use.
MODULE 05 / 9 · CONCEPT EXPLAINED

Mixins for reusable declaration patterns

A mixin inserts a reusable block of CSS declarations and can accept parameters or content. Use it when several components share a genuine pattern, not merely to give every rule a new name. Check the compiled output to avoid duplicating large blocks unnecessarily.

Follow this example
@mixin focus-ring($color) {
  &:focus-visible { outline: 3px solid $color; outline-offset: 3px; }
}

.button { @include focus-ring(#245f4a); }
Try it yourself: Write one focus-ring mixin and apply it to a link and a button.
MODULE 06 / 9 · CONCEPT EXPLAINED

Functions, maps and token lookup

Functions return a value for use in another expression; maps group related key-value settings. Prefer Sass’s built-in module functions through @use "sass:map" and @use "sass:color" instead of deprecated global helpers. Validate that a requested map key exists so mistakes fail clearly.

Follow this example
@use 'sass:map';
$colors: ('brand': #245f4a, 'ink': #182538);

$brand: map.get($colors, 'brand');
.badge { color: $brand; }
Try it yourself: Create a color map and use map.get to style two components.
MODULE 07 / 9 · CONCEPT EXPLAINED

Loops and generated utilities

Control directives such as @each, @for and @if generate CSS based on data. They can help produce a family of utilities, but broad generation can bloat stylesheets. Generate only classes your design system needs and inspect the output before shipping.

Follow this example
$spaces: (1: .25rem, 2: .5rem, 3: 1rem);

@each $key, $value in $spaces {
  .gap-#{$key} { gap: $value; }
}
Try it yourself: Generate three spacing utility classes from a Sass map and review the emitted CSS.
MODULE 08 / 9 · CONCEPT EXPLAINED

Responsive components and CSS custom properties

Use Sass to organize source and CSS custom properties when a value should respond to runtime themes or component state. Media queries can be written in nested component context; keep breakpoints consistent and consider the content rather than specific devices.

Follow this example
$card-padding: 1rem;
.card {
  padding: $card-padding;
  @media (min-width: 48rem) { padding: $card-padding * 1.5; }
}
Try it yourself: Create a card that increases its padding at one content-driven breakpoint and compare the CSS output.
MODULE 09 / 9 · CONCEPT EXPLAINED

Compile, debug and ship maintainable SCSS

Run Dart Sass in watch mode while authoring and use source maps during development when available. Compile in CI or the build pipeline so deployed pages receive CSS. Treat compiler warnings as migration signals, and do not ship Sass source maps if they expose private source or paths.

Follow this example
# One-time compilation
sass src/scss:public/css

# Recompile when source files change
sass --watch src/scss:public/css
Try it yourself: Organize a small interface into tokens, base, components and utilities; compile it and check every stylesheet loads in the browser.
PUT THE MODULES TOGETHER

Your final project

Build a small Sass design system with token modules, reusable component mixins and generated CSS utilities. Write down what the project should do, build it in small steps, and include a README that explains how to run it.

Find a guided course →

Official documentation and further reading

Use primary documentation for current language rules and version changes. The examples in this guide are learning starting points; verify details for the exact runtime and browser support your project needs.

Frequently asked questions

Are Sass and SCSS different languages?

SCSS is one syntax supported by Sass. The indented .sass syntax is the other; both compile to CSS.

Can a browser read SCSS directly?

No. Compile SCSS to CSS before serving it to the browser.