Preprocessor History
For years, CSS lacked features that developers needed for large projects: variables, nesting, reusable blocks of styles, and color manipulation. Preprocessors like Sass (2006) and Less (2009) filled those gaps by letting you write in an extended language that compiled down to plain CSS. They shaped the way an entire generation of developers thought about stylesheets, and many of the features they pioneered have since been adopted into native CSS.
This activity is entirely hands-on exploration. You will not install anything or submit anything. Open the online playgrounds linked below, try each snippet, and pay attention to how each preprocessor feature maps (or does not map) to what CSS can do natively today.
The Playgrounds
Use these online compilers to experiment with the snippets on this page. Each one lets you type preprocessor code on one side and see the compiled CSS output on the other, with no local installation required.
- Sass: sass-lang.com/playground
- Less: lesscss.org/less-preview
Open both playgrounds now so you can switch between them as you work through each section.
Variables
Before CSS had custom properties, preprocessors were the only way to store a value once and reuse it across a stylesheet. Both Sass and Less introduced variables early on, and they remain one of the most recognizable preprocessor features.
Sass Variables
Sass uses a $ prefix. Variables are resolved at compile time and disappear from the final CSS output.
// Paste this into the Sass playground
$brand-color: #3a86ff;
$spacing: 1.5rem;
$radius: 0.5rem;
.card {
background: $brand-color;
padding: $spacing;
border-radius: $radius;
}
Less Variables
Less uses an @ prefix. The behavior is similar: values are substituted at compile time.
// Paste this into the Less playground
@brand-color: #3a86ff;
@spacing: 1.5rem;
@radius: 0.5rem;
.card {
background: @brand-color;
padding: @spacing;
border-radius: @radius;
}
Native CSS Today
CSS custom properties (also called CSS variables) are declared with a -- prefix and accessed with var(). Unlike preprocessor variables, they exist at runtime, participate in the cascade, and can be changed dynamically with JavaScript or overridden in different scopes.
:root {
--brand-color: #3a86ff;
--spacing: 1.5rem;
--radius: 0.5rem;
}
.card {
background: var(--brand-color);
padding: var(--spacing);
border-radius: var(--radius);
}
The key difference is timing. Preprocessor variables are gone after compilation. CSS custom properties survive into the browser and can be changed at runtime, which makes them far more powerful for theming, responsive adjustments, and component-level overrides. You will explore this in depth in the Custom Properties and Token Thinking reading.
Nesting
Nesting lets you write child selectors inside their parent instead of repeating the parent selector on every rule. This was one of the most popular reasons developers reached for a preprocessor.
Sass Nesting
Sass compiles nested selectors into the flat descendant selectors the browser expects. The & character references the parent selector, which is essential for pseudo-classes and modifier patterns.
// Paste this into the Sass playground
.nav {
background: #333;
ul {
list-style: none;
margin: 0;
padding: 0;
}
a {
color: white;
text-decoration: none;
&:hover {
color: #3a86ff;
}
}
&.sticky {
position: fixed;
top: 0;
}
}
Less Nesting
Less uses the same nesting syntax and & parent reference. The compiled output is identical.
// Paste this into the Less playground
.nav {
background: #333;
ul {
list-style: none;
margin: 0;
padding: 0;
}
a {
color: white;
text-decoration: none;
&:hover {
color: #3a86ff;
}
}
&.sticky {
position: fixed;
top: 0;
}
}
Native CSS Today
Native CSS nesting landed in all major browsers in 2023. The syntax is very close to what Sass and Less established. The & character works the same way for parent references, and you can nest media queries directly inside a rule.
.nav {
background: #333;
ul {
list-style: none;
margin: 0;
padding: 0;
}
a {
color: white;
text-decoration: none;
&:hover {
color: #3a86ff;
}
}
&.sticky {
position: fixed;
top: 0;
}
}
Try pasting the native version into your browser's DevTools on any page. It works without any compilation step. You can check current browser support on Can I Use: CSS Nesting.
Color Helpers
Preprocessors gave developers functions to manipulate colors mathematically: lighten, darken, saturate, mix, and more. These were invaluable for generating consistent color palettes from a single base value.
Sass Color Functions
// Paste this into the Sass playground
$primary: #3a86ff;
.button {
background: $primary;
color: white;
&:hover {
background: darken($primary, 15%);
}
}
.badge {
background: mix($primary, white, 25%);
}
.overlay {
background: rgba($primary, 0.5);
}
Less Color Functions
// Paste this into the Less playground
@primary: #3a86ff;
.button {
background: @primary;
color: white;
&:hover {
background: darken(@primary, 15%);
}
}
.badge {
background: mix(@primary, white, 25%);
}
.overlay {
background: fade(@primary, 50%);
}
Native CSS Today
CSS now has color-mix() for blending colors, oklch() for perceptually uniform color spaces, and relative color syntax for channel adjustments. These work at runtime and respond to custom property changes, something preprocessor functions could never do.
:root {
--primary: #3a86ff;
}
.button {
background: var(--primary);
color: white;
&:hover {
/* Darken by mixing with black */
background: color-mix(in oklch, var(--primary) 70%, black);
}
}
.badge {
/* Lighten by mixing with white */
background: color-mix(in oklch, var(--primary) 25%, white);
}
.overlay {
background: oklch(from var(--primary) l c h / 0.5);
}
The color-mix() function is supported in all modern browsers. You can experiment with it on the MDN color-mix() reference. The oklch() color space and relative color syntax are covered in detail in the Unit 3: Modern Color Functions reading.
Mixins
Mixins are reusable blocks of declarations that you can include in any selector. They were essential in the era when vendor prefixes cluttered every stylesheet and common patterns like clearfix required multiple declarations. Sass and Less both support them, though with slightly different syntax.
Sass Mixins
// Paste this into the Sass playground
@mixin flex-center {
display: flex;
align-items: center;
justify-content: center;
}
@mixin responsive-grid($min-col: 250px) {
display: grid;
grid-template-columns: repeat(auto-fit, minmax($min-col, 1fr));
gap: 1rem;
}
.hero {
@include flex-center;
min-height: 60vh;
}
.card-grid {
@include responsive-grid(300px);
}
Less Mixins
// Paste this into the Less playground
.flex-center() {
display: flex;
align-items: center;
justify-content: center;
}
.responsive-grid(@min-col: 250px) {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(@min-col, 1fr));
gap: 1rem;
}
.hero {
.flex-center();
min-height: 60vh;
}
.card-grid {
.responsive-grid(300px);
}
Native CSS Today
CSS does not have a direct equivalent to mixins yet. There is a proposal for @mixin and @apply working its way through the CSS Working Group, but it is not implemented in any browser. In the meantime, custom properties and utility classes cover many of the same use cases. Vendor prefixes are also far less necessary today thanks to broad browser alignment on modern features and tools like Autoprefixer that handle the remaining cases automatically.
:root {
--min-col: 250px;
}
/* No mixin needed: write the pattern directly */
.hero {
display: flex;
align-items: center;
justify-content: center;
min-height: 60vh;
}
.card-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(var(--min-col), 1fr));
gap: 1rem;
}
For patterns you repeat often, a utility class or a well-named custom property set can serve a similar role. The lack of native mixins is one of the few remaining reasons some teams still use a preprocessor.
Reflection
There is nothing to submit for this activity, but take a few minutes to think about what you observed:
- Which preprocessor features does native CSS now handle just as well or better?
- Which features are still missing from native CSS, and how significant is that gap?
- If you were starting a brand new project today with no legacy code, would you reach for a preprocessor? Why or why not?
Keep these questions in mind as you move through the rest of Unit 1. The next readings on custom properties, math functions, and nesting will show you how far native CSS has come and where the remaining gaps are shrinking.