Episode 1 — Fundamentals / 1.7 — Working With SASS

1.7.a — What Is SASS?

In one sentence: SASS is a CSS preprocessor that adds variables, nesting, mixins, functions, and logic to your stylesheets — then compiles everything down to plain CSS that any browser can understand.

Navigation: ← 1.7 Overview · 1.7.b — SCSS vs SASS & Setup →


1. The problem SASS solves

Plain CSS is powerful, but at scale it hits pain points:

Pain pointExample
Repeated valuesThe same brand color hex copied across 40 files
No nestingFlat selectors like .card .card-header .card-title repeated everywhere
No reuse mechanismThe same media-query breakpoint pattern pasted in dozens of places
No logicCannot loop to generate utility classes (mt-1, mt-2, … mt-10)
File organizationOne giant CSS file or manual <link> stacking with no dependency graph

Preprocessors solve all five. SASS is the oldest and most widely adopted.


2. Key features at a glance

FeatureWhat it doesQuick example
VariablesStore values once, reuse everywhere$primary: #3b82f6;
NestingWrite child selectors inside parent blocks.nav { a { color: $primary; } }
Partials & ImportsSplit code into small files, combine at build@use 'abstracts/variables';
MixinsReusable blocks of declarations you @include@mixin flex-center { … }
FunctionsCompute and return values@function rem($px) { @return … }
OperatorsMath inside stylesheetswidth: 100% / 3;
Control flow@if, @for, @each, @whileGenerate grids, palettes, utilities
InheritanceShare rules via @extend%btn-base { padding: … }

3. SASS vs plain CSS

┌─────────────────────────────────────────────────────────┐
│                  You write (.scss)                       │
│                                                         │
│  $primary: #3b82f6;                                     │
│  .btn {                                                 │
│    background: $primary;                                │
│    &:hover { background: darken($primary, 10%); }       │
│  }                                                      │
└────────────────────┬────────────────────────────────────┘
                     │  sass --watch src:dist
                     ▼
┌─────────────────────────────────────────────────────────┐
│               Browser receives (.css)                   │
│                                                         │
│  .btn { background: #3b82f6; }                          │
│  .btn:hover { background: #2563eb; }                    │
└─────────────────────────────────────────────────────────┘

The browser never sees SCSS. SASS is a build-time tool — it produces standard CSS before deployment.


4. The compilation concept

  1. You write .scss (or .sass) files during development.
  2. A compiler (dart-sass) reads those files.
  3. It resolves variables, evaluates functions, expands mixins, and flattens nesting.
  4. It outputs .css files the browser understands.
  5. Optionally generates source maps so DevTools map back to your SCSS lines.
src/
  styles/
    main.scss        ← you edit this
    _variables.scss
    _buttons.scss

dist/
  styles/
    main.css         ← compiler generates this
    main.css.map     ← source map (optional)

5. Brief history

YearMilestone
2006Hampton Catlin creates SASS (Ruby-based, indentation syntax)
2009SCSS syntax introduced (CSS-compatible curly braces)
2014LibSass (C/C++) brings faster compilation
2016Dart Sass becomes the reference implementation
2019@use / @forward module system replaces @import
2022LibSass and Node Sass officially deprecated — Dart Sass is the only supported compiler

6. SASS vs other preprocessors

SASS/SCSSLessStylus
SyntaxSCSS (CSS-like) or indentedCSS-likeFlexible (optional braces/semicolons)
FeaturesFull: loops, conditionals, modulesVariables, mixins, functionsVariables, mixins, conditionals
EcosystemLargest — Bootstrap, Tailwind (build), most frameworksBootstrap 3 used LessSmaller community
CompilerDart (fast, maintained)JavaScriptJavaScript
Module system@use / @forward (namespaced)@import only@import / @require

SCSS dominates modern front-end. When a job listing says "SASS experience," they almost always mean SCSS syntax.


7. Key takeaways

  1. SASS is a build tool — it extends CSS with programming features, then compiles to plain CSS.
  2. SCSS is the modern, CSS-compatible syntax (curly braces + semicolons). The indented .sass syntax is rarely used today.
  3. Dart Sass is the only actively maintained compiler. Node Sass and LibSass are deprecated.
  4. Features — variables, nesting, mixins, functions, control flow, partials — solve real CSS maintenance problems.
  5. The browser receives standard CSS. SASS adds zero runtime cost.

Explain-It Challenge

Explain without notes:

  1. Why would a team choose SCSS over plain CSS for a large project? Name three specific problems it solves.
  2. What does "compilation" mean in the context of SASS — what goes in and what comes out?
  3. Why is Dart Sass the recommended compiler today (what happened to Node Sass)?

Navigation: ← 1.7 Overview · 1.7.b — SCSS vs SASS & Setup →