What are CSS preprocessors (SASS)?
A CSS preprocessor is a language that extends CSS with programming features and compiles to plain CSS during the build. Sass (with its SCSS syntax) is the most popular; it adds variables, nesting, mixins, functions, loops, partials and modules, which made large stylesheets far easier to maintain before CSS gained many of these features natively.
Key Sass features
- Variables:
$brand: #2b4bff; - Nesting:
.card { &:hover { ... } .title { ... } } - Mixins: reusable blocks with arguments,
@mixin focus-ring($c) { ... }used with@include. - Functions and math:
math.div(),color.adjust(). - Control flow:
@each,@for,@ifto generate utility classes. - Modules: split code into partials (
_buttons.scss) and load them with@use/@forward(namespaced;@importis deprecated). @extendfor sharing selectors (use sparingly; it can bloat output).
Other options
Less and Stylus (older preprocessors), and PostCSS, a plugin-based post-processor that adds autoprefixing, future CSS syntax, and powers Tailwind.
Do you still need Sass?
Native CSS now has custom properties (dynamic at runtime, unlike Sass variables), nesting, color-mix(), @layer, @container, and math with calc(), min(), max() and clamp(). Many new projects use plain CSS plus PostCSS, CSS Modules or Tailwind. Sass remains common in existing codebases and design systems that rely on mixins and loops.
Interview tip
Explain the difference: Sass variables are compile-time constants; CSS custom properties live in the browser and can change with media queries, themes or JavaScript.
Code example
1// _tokens.scss2$brand: #2b4bff;3$radius: 8px;4$sizes: (sm: 0.875rem, md: 1rem, lg: 1.25rem);56// _mixins.scss7@mixin focus-ring($color: $brand) {8 outline: 3px solid $color;9 outline-offset: 2px;10}1112// button.scss13@use "sass:color";1415.btn {16 background: $brand;17 color: white;18 border-radius: $radius;19 padding: 0.5em 1em;2021 &:hover { background: color.adjust($brand, $lightness: -8%); }22 &:focus-visible { @include focus-ring; }2324 // Generates .btn--sm, .btn--md, .btn--lg25 @each $name, $size in $sizes {26 &--#{$name} { font-size: $size; }27 }28}29/* Compiled CSS output (excerpt):30.btn { background: #2b4bff; color: white; border-radius: 8px; padding: .5em 1em; }31.btn--sm { font-size: .875rem; }32.btn--md { font-size: 1rem; } */
Practice this question
Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the HTML & CSS set.