Code Snippets
/

CSS Preprocessor Features Cheat Sheet

CSS Preprocessor Features Cheat Sheet

If you have used SCSS or Less, you know variables, nesting, and mixins as preprocessor features. Native CSS now offers all three: custom properties (`--var`), the CSS Nesting Module, and `@layer`. This snippet shows the SCSS form alongside the native form for each so you can see when you actually need a preprocessor and when plain CSS is enough. Audience: practitioners moving from SCSS to native CSS and wondering what they get to drop.

CSS
Medium
3 snippets
css-preprocessors
css-variables
css-selectors

967 views

21

/* SCSS */
/* SCSS variables are compile-time substitutions. They cannot be changed at
   runtime, cannot be inspected in DevTools, and cannot vary by selector scope. */
/*
$primary: royalblue;
$radius: 6px;

.button {
    background: $primary;
    border-radius: $radius;
}
*/

/* Native CSS */
/* Custom properties are runtime values. They live in the cascade, can be
   redefined per selector, and JavaScript can read or write them. */
:root {
    --primary: royalblue;
    --radius: 6px;
}

.button {
    background: var(--primary);
    border-radius: var(--radius);
}

/* Scoped override: a card with a different accent color, no extra class needed
   on every nested element. SCSS variables cannot do this. */
.card.danger {
    --primary: crimson;
}

.card.danger .button {
    /* Picks up the locally-redefined --primary automatically. */
    background: var(--primary);
}

SCSS variables are resolved by the compiler before the browser ever sees the CSS, which makes them feel like constants in a programming language. Native custom properties are part of the cascade, which is far more powerful: redefining --primary on .card.danger automatically flows down to every descendant that reads var(--primary), with no extra selector multiplication. Custom properties also let JavaScript do element.style.setProperty('--primary', '#fff') for runtime theming. The one place SCSS variables still win is loops and arithmetic at build time; for everything else, native is simpler and more powerful.