Sass / SCSS Introduction
Sass (Syntactically Awesome StyleSheets) is a CSS preprocessor: a language that extends CSS with features like variables, nesting, mixins, and functions, and then compiles down to plain CSS before it ever reaches a browser. The browser never sees Sass — it only ever sees the ordinary CSS that a compiler step produced from it.
Two syntaxes, one language
.sass) drops curly braces and semicolons in favor of significant whitespace, similar in spirit to Python:// Indented Sass syntax (.sass) — no braces, no semicolons
.card
padding: 1rem
border-radius: 8px
.card-title
font-weight: 600.scss) is a superset of ordinary CSS syntax — braces and semicolons included — which means any valid plain CSS file is already valid SCSS. This is the syntax that dominates in practice today:// SCSS syntax (.scss) — CSS-like braces and semicolons
.card {
padding: 1rem;
border-radius: 8px;
.card-title {
font-weight: 600;
}
}.scss syntax, not the older indented .sass syntax. The rest of this Sass series on this site uses SCSS exclusively, since that's what you'll encounter in the overwhelming majority of real codebases, tutorials, and framework source code.Why Sass existed in the first place
Sass was created in 2006, at a time when plain CSS had no variables, no nesting, no way to define a reusable block of declarations, and no way to compute a value from another value. Every large stylesheet ended up full of repeated color codes, repeated spacing values, and repeated selector prefixes with no way to abstract any of it. Sass filled exactly those gaps.
Gap in old CSS | Sass feature that filled it |
|---|---|
No variables |
|
No nesting | Nested selector blocks with |
No reusable declaration blocks |
|
No computed values |
|
No sharing across files without one giant file |
|
Installing and compiling Sass
Sass needs a compile step somewhere in your toolchain. The most common path today is the Dart Sass command-line tool, installed via npm, either run directly or wired into a bundler (Vite, webpack, or a framework's built-in Sass support).
# Install Dart Sass as a dev dependency npm install --save-dev sass # Compile once npx sass styles.scss styles.css # Watch for changes during development npx sass --watch styles.scss:styles.css
sass-loader, Vite's built-in Sass support, or Next.js's built-in Sass support) handles compilation automatically as part of the normal build.Where this series goes next
Sass Variables & Nesting —
$variablesand nested selectors, and how they differ from native equivalents.Sass Mixins & Functions — reusable declaration blocks and computed values.
Sass @extend & Placeholders — sharing styles by combining selectors.
Sass Partials & @use / @forward — splitting Sass across files with a real module system.
Sass Control Directives —
@if,@for, and@eachfor logic inside a stylesheet.