Preprocessors and Tooling: Sass, PostCSS, Lightning CSS and What Native CSS Replaced
What CSS build tools do and whether you still need them: Sass variables, nesting, partials, mixins, @extend and loops versus native replacements, PostCSS with Autoprefixer, Lightning CSS lowering for older browsers, and source maps.
kvi5hnuCode Sprout team member9 min readOn this page
Browsers only understand CSS, but the CSS you write doesn't have to be the CSS you ship. Build tools sit in between: they take source files and produce a stylesheet. Preprocessors like Sass add a language on top of CSS. Postprocessors like PostCSS and Lightning CSS take CSS and transform it: adding prefixes, converting new syntax for older browsers, and minifying. Many preprocessor features have since become native CSS, so the question today is which tools you still need.
All the compiled output in this article was produced by the real tools: Sass 1.108 and Lightning CSS.
Sass
Sass is the most widely used preprocessor. It has two syntaxes: SCSS (.scss), a superset of CSS with braces and semicolons, which almost everyone uses, and the older indented syntax (.sass). Less and Stylus are similar languages, with minor differences such as @name instead of $name for variables in Less.
npm install --save-dev sass
npx sass src/index.scss build/styles.css # add --watch to recompile on save
Bundlers such as Vite compile .scss files automatically once the sass package is installed.
Variables
$brand: #8a3b12;
.button { background: $brand; }
Sass variables are replaced at build time; the browser never sees them. That's the essential difference from custom properties:

Setting $accent inside .promo only changes the variable for the rest of that block during compilation. Since the block has no declarations, Sass dropped it from the output entirely. A custom property, by contrast, is a real property that inherits, so it can change per element, per media query, per theme, or from JavaScript (article 27). Many projects use both: Sass variables for build-time constants, custom properties for anything that varies.
Nesting
.card {
padding: 1rem;
&__title { font-weight: 700; } /* .card__title: name concatenation */
&:hover { background: #f4efe6; }
@media (width >= 40rem) { padding: 2rem; }
}
Native CSS nesting (article 21) now handles everything here except &__title: CSS nests selectors, it doesn't paste strings together. Sass always flattens nesting into plain selectors, so its output works in any browser.
Partials and modules
Files starting with an underscore, like _button.scss, are partials: they're not compiled on their own but loaded into another file, so you can organize CSS in many files and still ship one.
@use "tokens"; /* loads _tokens.scss; its members are tokens.$brand */
@use "button";
.title { color: tokens.$brand; }
@use replaced Sass's old @import, which is deprecated and will be removed in Dart Sass 3.0. The compiler says so when you use it:
DEPRECATION WARNING [import]: Sass @import rules are deprecated and will be removed in Dart Sass 3.0.0.
Mixins and @extend
A mixin is a reusable group of declarations, optionally with parameters:
@mixin alert($fg, $bg) { color: $fg; background: $bg; border: 1px solid $fg; }
.alert--error { @include alert(#5c1515, #fbe9e9); }
@extend looks similar but works differently: it doesn't copy declarations; it adds the selector to the extended rule, wherever that rule is. That can change which rule wins:

.message--error sets its own color after extending .alert, but in the output, its selector joined the .alert rule, which comes later in the file, so navy wins. With @include, the declarations are copied in place and the later firebrick wins as expected. Prefer mixins, or plain modifier classes in the HTML. @extend also can't be used inside @media across rules, and it can produce long, surprising selector lists.
Functions, math and loops
@use "sass:color";
@use "sass:math";
$brand: #8a3b12;
.card {
border-color: color.adjust($brand, $lightness: 20%);
width: math.div(100%, 3);
}
@each $name, $size in (sm: 0.875rem, md: 1rem, lg: 1.25rem) {
.text-#{$name} { font-size: $size; }
}
Sass 1.108 compiled that to:
.card {
border-color: rgb(88.5972850679%, 38.5520361991%, 12.5791855204%);
width: 33.3333333333%;
}
.text-sm { font-size: 0.875rem; }
.text-md { font-size: 1rem; }
.text-lg { font-size: 1.25rem; }
Old global functions such as darken() and lighten() still work but print deprecation warnings that suggest color.adjust() or color.scale(). Division with / has been replaced by math.div(), because / is also a CSS separator, as in grid-area: 1 / 3.
Loops (@each, @for) and conditionals (@if) generate repetitive CSS, like a set of utility classes. That's one of the few things CSS itself still can't do.
What native CSS replaced
| Preprocessor feature | Native CSS | Support |
|---|---|---|
| variables | custom properties (article 27), typed with @property (article 28) | all browsers |
| nesting | CSS nesting (article 21), without name concatenation | all browsers |
| color functions | color-mix() and relative colors (article 33) | all browsers |
| math | calc(), min(), max(), clamp(), round(), mod() (article 26) | all browsers |
| partials | @import with layer(), or a bundler that inlines imports | all browsers |
| conditionals | if() (article 30) | Chrome 137, Safari 27.3 |
| functions | @function (article 30) | Chrome 139, Safari 27.3 |
| mixins | @mixin and @apply (CSS Mixins draft) | only behind a flag in Chrome 141+ |
| loops | none; sibling-index() and sibling-count() cover some cases (article 30) | all browsers (Firefox since 154) |
The native versions are often more powerful, because they run in the browser: color-mix(in oklab, var(--accent), white 20%) follows the current theme, which a Sass color function never can. What's left for Sass is mostly loops, mixins, compile-time logic, and existing codebases built on it.
PostCSS
PostCSS isn't a language. It parses CSS into a tree and runs plugins over it, and does nothing without them. Common plugins:
- Autoprefixer adds vendor prefixes, like
-webkit-user-select, only where the browsers you support need them. Supported browsers come from a Browserslist query, such as"> 0.5%, last 2 versions, not dead"inpackage.jsonor a.browserslistrcfile, checked against compatibility data. - postcss-preset-env converts newer syntax for older browsers, based on the same Browserslist targets.
- cssnano minifies: it removes whitespace and comments, shortens values and merges rules.
- Tools such as Tailwind CSS and CSS Modules have historically run as PostCSS plugins too.
Plugin order matters, since each plugin sees the previous one's output.
Lightning CSS
Lightning CSS is a fast tool, written in Rust, that combines prefixing, syntax lowering, bundling of @import and minification. You give it targets, and it converts only what those browsers don't support:
.card {
color: oklch(45% 0.12 44);
& .title { color: color-mix(in oklab, currentColor 70%, white); }
&:hover { translate: 0 -2px; }
}
@media (width >= 40rem) { .card { user-select: none; } }
With targets chrome 100, safari 15, firefox 100, Lightning CSS produced:
.card {
color: #893a10;
color: lab(35.3169% 33.0409 40.4831);
}
.card .title {
color: color-mix(in oklab, currentColor 70%, white);
}
.card:hover {
translate: 0 -2px;
}
@media (min-width: 40rem) {
.card {
-webkit-user-select: none;
user-select: none;
}
}
It flattened the nesting, rewrote the range media query as min-width, added the prefix Safari 15 needs, and turned the oklch() color into a hex fallback followed by lab(). It left color-mix() with currentColor alone, because the result depends on the element's color and can't be computed at build time. Build tools can't fix everything.
Vite can use Lightning CSS instead of PostCSS (css.transformer: 'lightningcss'), and Tailwind CSS 4 uses it internally.
Source maps
Compiled CSS no longer matches the file you edited. A source map is a separate .map file that maps every position in the output back to the source, so DevTools can show _button.scss:12 instead of styles.css:940. Sass, PostCSS and Lightning CSS all generate them. Ship them to development builds, and to production only if you're happy for anyone to see your source.
Do you still need a build step?
- No preprocessor: for many new projects, native custom properties, nesting,
color-mix(), layers and@importcover what Sass was used for. - A postprocessor is still useful for minification and bundling (one request, smaller file), for prefixes if you support older browsers, and for lowering new syntax for them.
- Sass is still reasonable for large existing codebases and for generating CSS with loops. Mixing approaches is common: Sass for structure, custom properties for runtime values.
/* variables: runtime custom properties instead of $accent */
:root { --accent: #1d4ed8; --space: 0.8rem; }
.promo { --accent: #b45309; }
/* a function: Chrome 139+; elsewhere the fallback declaration applies */
@function --half(--x) { result: calc(var(--x) / 2); }
.card {
/* math instead of Sass arithmetic */
padding: var(--space);
margin-block-end: calc(var(--space) * 0.75);
border: 1px solid color-mix(in oklab, var(--accent) 35%, white); /* instead of lighten() */
border-radius: 10px;
background: color-mix(in oklab, var(--accent) 6%, white);
/* native nesting instead of Sass nesting */
& .card-title { margin: 0; color: var(--accent); font-size: 1.05rem; }
& p { margin: 0.3rem 0 0.6rem; }
&:hover { border-color: var(--accent); }
}
.button {
border: 0; border-radius: 6px; color: white; font: 600 0.85rem system-ui, sans-serif;
background: var(--accent);
padding: 0.5em 0.9em;
padding: --half(var(--space)) var(--space);
}
.button:hover { background: oklch(from var(--accent) calc(l - 0.08) c h); } /* instead of darken() */
body { font: 0.85rem system-ui, sans-serif; margin: 1rem; }
.note { color: #555; }
No build step is involved: the accent changes per section because it's a custom property, the border and hover colors are derived in the browser, and the nesting is native. @function works in Chrome 139 and Safari 27.3; other browsers use the earlier padding declaration.
What's current
- Dart Sass is the only maintained Sass implementation; LibSass and node-sass are deprecated. Sass
@importand global functions likedarken()are deprecated, to be removed in Dart Sass 3.0. - Lightning CSS and PostCSS with Autoprefixer are the common postprocessors; many bundlers include one by default.
- Native
if()and@functionwork in Chrome and Safari 27.3; CSS mixins (@mixin,@apply) are only behind Chrome's experimental features flag.
Common questions
Should I replace Sass variables with custom properties? For anything that changes at runtime (themes, per-section values, media queries), yes. Pure constants can stay in Sass if you already use it.
Why does Sass complain about /?
Slash division is deprecated because / is also a separator in CSS. Use math.div() or calc().
Do I still need Autoprefixer?
Only for prefixes your supported browsers still need, such as -webkit-user-select for older Safari. With a modern Browserslist query, it adds very little.
Can a build tool make new CSS work in old browsers?
Partly. Syntax like nesting, range media queries and some colors can be rewritten. Features that depend on runtime values, like color-mix() with custom properties, container queries or :has(), can't.
Summary
- Sass adds variables, nesting, partials, mixins,
@extend, functions and loops, all resolved at build time. - Sass variables are constants in the output; custom properties stay live in the browser.
- Prefer
@includeor modifier classes over@extend, whose output order can change which rule wins. - Native CSS now covers variables, nesting, color manipulation and math, with
if()and@functionarriving. - PostCSS (with Autoprefixer, cssnano) and Lightning CSS prefix, lower and minify CSS for chosen targets.
- Source maps link compiled CSS back to the source in DevTools.
Practice questions
This Sass doesn't make the button in .dark white. Why, and what's the native fix?
$fg: black;
.button { color: $fg; }
.dark { $fg: white; }
Answer
Sass replaces $fg when compiling; the assignment inside .dark has no output, so .button is always black. Use a custom property:
:root { --fg: black; }
.dark { --fg: white; }
.button { color: var(--fg); }
Rewrite this with native CSS.
.nav {
a { color: darken($brand, 10%); }
a:hover { color: $brand; }
}
Answer
.nav {
& a { color: oklch(from var(--brand) calc(l - 0.1) c h); }
& a:hover { color: var(--brand); }
}
Why can't Lightning CSS convert color-mix(in oklab, currentColor 70%, white) for older browsers?
Answer
The result depends on each element's current text color, which is known only in the browser. A build tool can only precompute values that are fixed in the source.
Which feature still needs a preprocessor in CSS today?
Answer
Loops that generate rules, such as a set of utility classes from a list of sizes. CSS has no loop construct. Native mixins also aren't usable yet: they're only behind a flag in Chrome.
Previous: Pattern Libraries, a CSS-First Workflow and Refactoring Safely
Next: CSS At-Rules Reference: @import, @namespace, @media, @supports, @layer and the Rest

More in CSS Course
Quiz: CSS Delicate Details
Twenty-five questions on the edge cases that surprise experienced developers: invalid custom properties, shorthands that reset values, layer order with !important, containing blocks, margin collapsing, specificity of :is() and :where(), intrinsic minimum sizes, and more, each checked in Chrome.
Quiz: CSS Interview Questions
Thirty front-end interview questions: cascade, specificity and layers, box model and margin collapsing, stacking contexts, positioning, flexbox and grid, responsive design, custom properties, performance, accessibility, modern selectors and architecture.
Quiz: CSS Course Final Exam
Thirty questions across the whole CSS course: syntax and error handling, selectors, the cascade and layers, values and units, color, the box model, backgrounds, positioning, flexbox, grid, responsive design, typography, generated content, effects, transforms, motion and architecture.
Quiz: CSS Architecture, Tooling and Debugging (CSS Part 17)
Twenty questions on modular CSS and BEM, layering a stylesheet, design tokens and theming, pattern libraries and safe refactoring, preprocessors and build tools, the at-rules reference, and debugging common CSS problems.
Discussion
Sign in to ask a question or share what you learned.