Discover how grouping style values can save you hours of tedious updates!
Why Maps for grouped values in SASS? - Purpose & Use Cases
Imagine you are styling a website with many colors and fonts. You write each color and font style separately everywhere in your CSS.
If you want to change a color or font, you must find and update every single place manually. This is slow and easy to miss some spots, causing inconsistent styles.
Using maps for grouped values lets you store related styles together in one place. You can change a value once, and all styles using it update automatically.
$primary-color: #333; $secondary-color: #666; $font-main: 'Arial', sans-serif; .button { color: $primary-color; font-family: $font-main; } .alert { color: $secondary-color; font-family: $font-main; }
$theme: (
colors: (
primary: #333,
secondary: #666
),
fonts: (
main: 'Arial', sans-serif
)
);
.button {
color: map-get(map-get($theme, 'colors'), 'primary');
font-family: map-get(map-get($theme, 'fonts'), 'main');
}
.alert {
color: map-get(map-get($theme, 'colors'), 'secondary');
font-family: map-get(map-get($theme, 'fonts'), 'main');
}You can organize and update your styles easily, keeping your design consistent and your code clean.
A design system where colors, fonts, and spacing are grouped in maps, so changing the brand color updates the entire website instantly.
Manual style updates are slow and error-prone.
Maps group related style values in one place.
Changing a map value updates all uses automatically.