Sass Introduction
Sass (Syntactically Awesome Style Sheets) is a language that compiles to CSS. You write styles with extra features — variables, nesting, reusable mixins, functions, loops and modules — and the Sass compiler turns them into the plain CSS that browsers understand.
Browsers never see Sass. It is a build-time tool: your .scss files go in, a .css file comes out.
styles.scss ──► Sass compiler ──► styles.css ──► browserWhy use Sass?
Plain CSS has improved a lot (it now has custom properties, nesting and calc()), but large stylesheets still get repetitive. Sass helps you:
| Problem in plain CSS | Sass feature that solves it |
|---|---|
| The same colour copied into 40 rules | Variables ($brand: #cc6699;) |
| Long, repeated selector prefixes | Nesting |
| Copy-pasted groups of declarations | Mixins (@mixin / @include) |
| One giant file | Partials and the module system (@use) |
| Generating many similar classes by hand | Loops (@each, @for) |
| Computing sizes and colour shades | Functions and built-in modules (sass:math, sass:color) |
Two syntaxes: SCSS and indented
Sass has two syntaxes. SCSS (.scss) is a superset of CSS: every valid CSS file is also valid SCSS, and it uses braces and semicolons. The older indented syntax (.sass) uses indentation instead of braces. This course uses SCSS, which is what almost every project uses today.
// Indented syntax (.sass) – shown for recognition only
$brand: #cc6699
.button
color: $brandYour first Sass program
Press ▶ Run to compile the SCSS. The output panel shows the CSS the compiler produces. Below it, a preview renders some HTML using that CSS.
$brand: #cc6699;
$radius: 8px;
.button {
background: $brand;
color: white;
padding: 10px 18px;
border-radius: $radius;
border: none;
&:hover {
opacity: 0.85;
}
}.button {
background: #cc6699;
color: white;
padding: 10px 18px;
border-radius: 8px;
border: none;
}
.button:hover {
opacity: 0.85;
}
Notice two things in the output:
$brandand$radiusare gone — their values were substituted. Sass variables exist only at compile time.- The nested
&:hoverblock became a separate.button:hoverrule.
Tip: Every playground in this course is editable. Change
$brandtotealand press Ctrl+Enter to recompile.
Sass is a superset of CSS
Because SCSS accepts any CSS, you can rename styles.css to styles.scss and start adding Sass features gradually. Plain CSS passes straight through:
h1 {
font-family: system-ui, sans-serif;
color: #333;
}
.note {
border-left: 4px solid #cc6699;
padding: 8px 12px;
}h1 {
font-family: system-ui, sans-serif;
color: #333;
}
.note {
border-left: 4px solid #cc6699;
padding: 8px 12px;
}
Which Sass?
There have been several implementations over the years. Dart Sass is the official, actively developed one; the old Ruby Sass and LibSass (node-sass) are deprecated. This course targets modern Dart Sass (1.9x and later) and its module system (@use, @forward, sass:math, sass:color …). Older tutorials that use @import, darken() or / for division show patterns that now produce deprecation warnings — you will learn the modern replacements.
Test yourself
What does the browser receive when you use Sass?
- The .scss file
- Plain compiled CSS
- A JavaScript bundle that interprets Sass
- Both the .scss and the .css file
Which statement about SCSS syntax is true?
- It uses indentation instead of braces
- Every valid CSS file is also valid SCSS
- It cannot contain plain CSS rules
- It must be written in .sass files
Which Sass implementation is the official, maintained one?
- Ruby Sass
- LibSass (node-sass)
- Dart Sass
- PostCSS