Performance: Why design systems need SASS
Using SASS in design systems affects CSS bundle size and rendering speed by enabling reusable styles and reducing duplication.
Jump into concepts and practice - no test required
$primary-color: #0055ff; $spacing: 0.625rem 1.25rem; .button { background-color: $primary-color; padding: $spacing; } .card { border-color: $primary-color; margin: $spacing; }
.button { background-color: #0055ff; padding: 10px 20px; } .card { border-color: #0055ff; margin: 10px 20px; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Repeated raw CSS values | Low | Low | Medium (due to larger CSS) | [X] Bad |
| SASS variables and mixins | Low | Low | Low (smaller CSS) | [OK] Good |
SASS?SASS?$primary-color: #3498db;.$base-color: #333;
@mixin button-style {
background-color: $base-color;
border-radius: 0.5rem;
}
.button {
@include button-style;
color: white;
}.button class in the compiled CSS?button-style sets background-color to $base-color, which is #333..button class includes the mixin, so its background color is #333.$font-size: 1.2rem
.title {
font-size: $font-size;
}$font-size: 1.2rem.SASS variables and mixins help when the primary brand color changes?