Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 39 ยท Getting Started

Introduction to Sass

Learn what Sass is, how it extends CSS with variables, nesting, mixins and functions, and why teams compile Sass into plain CSS for the browser.

CSS is a wonderful language for describing how a page looks, but it was designed for small documents. On a real project you repeat the same color in forty places, copy the same twelve lines for every button, and scroll through one enormous file looking for the rule you need. Sass (Syntactically Awesome Style Sheets) fixes that. It is a CSS preprocessor: you write in a richer language, and a compiler turns your files into ordinary CSS that every browser understands.

Sass is the oldest and most widely used preprocessor. It was created in 2006, it is maintained by the Sass team, and the reference implementation today is Dart Sass, which is what this tutorial uses. Every valid CSS file is already valid SCSS, so you can adopt Sass one line at a time.

The big idea: compile, then ship CSS

Browsers cannot read Sass. The workflow is always the same three steps:

  1. You write .scss (or .sass) files.
  2. A compiler converts them into .css files.
  3. The browser loads only the generated CSS.
flowchart LR
  A["styles.scss<br/>variables, nesting, mixins"] --> B["Sass compiler<br/>(Dart Sass)"]
  B --> C["styles.css<br/>plain CSS"]
  C --> D["Browser"]

Sass exists only at build time. Visitors never download it, so it adds zero bytes to your pages.

That last point matters: using Sass does not change how fast your site loads. It changes how pleasant your source code is.

Your first compile, right in this page

Every example in this tutorial runs the real Dart Sass compiler in your browser. The first run downloads the compiler (a few hundred kilobytes), so give it a couple of seconds. Edit the SCSS inside the template string and press Run again.

Compile your first SCSS

Look at what happened. You wrote the brand color once in a variable. Nested .btn and &:hover blocks became flat selectors such as .card .btn:hover. You even did a little math with * 0.5 (see Variables and operators).

What Sass adds to CSS

Sass in four ideas

Variables Store a color or size once.
Nesting Mirror your HTML structure.
Mixins Reuse blocks of styles.
Functions Compute values.

Everything compiles down to plain CSS.

1 / 2
  • Variables hold values you reuse ($brand, $gap).
  • Nesting lets child rules live inside their parent.
  • Partials and modules split one giant stylesheet into small files you combine with @use.
  • Mixins are reusable chunks of declarations, optionally with arguments.
  • Functions return a value, such as a computed color or a rem size.
  • Control directives (@if, @each, @for, @while) add logic.
  • Maps store key/value design tokens.
  • Built-in modules supply math, color, string, list and map helpers.

Sass versus native CSS features

Modern CSS now has custom properties (--brand), native nesting, and color-mix(). Do you still need Sass? Often yes, for different reasons:

Need Native CSS Sass
Reuse a value at runtime (theme switch) Custom properties Not possible: Sass values vanish at compile time
Reuse a value across many files at build time Awkward Variables and modules
Loop to generate 12 spacing classes Not available @for, @each
Reusable blocks with parameters Not available Mixins
Calculate a color shade at build time color-mix() at runtime color.adjust(), color.scale()
Split into files without extra requests @import makes extra requests @use bundles into one file

The best projects combine them: Sass computes and generates, custom properties carry the values that must change in the browser. You will see this pairing again in Modules and architecture.

SCSS or Sass syntax?

Sass has two syntaxes. SCSS looks like CSS, with braces and semicolons. The older indented syntax drops braces and semicolons and uses indentation. Almost everyone uses SCSS, and so does this tutorial. SCSS and the indented syntax compares them in detail.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does a Sass compiler produce?

    Sass is a preprocessor. It runs at build time and outputs ordinary CSS, which is the only thing the browser loads.
  2. 2. Which statement about Sass variables is true?

    Sass variables are replaced by their values when compiling. Use CSS custom properties for values that must change in the browser.
  3. 3. Is every valid CSS file also a valid SCSS file?

    SCSS was designed as a superset of CSS, so you can rename a .css file to .scss and start using Sass features gradually.
  4. 4. Which implementation of Sass is the reference one today?

    Dart Sass is actively maintained and gets every new feature first. Ruby Sass and LibSass (and Node Sass, which wrapped LibSass) are deprecated.

Summary

  • Sass is a preprocessor: you write Sass, a compiler outputs CSS, and browsers only see the CSS.
  • It adds variables, nesting, modules, mixins, functions, loops, maps and more.
  • SCSS is a superset of CSS, so you can adopt it gradually.
  • Sass values are resolved at build time; use custom properties for runtime changes.
  • Dart Sass is the current implementation, and it is what runs in this tutorial's examples.

Next: Installing and compiling Sass