Color Manipulation and Theme Calculations
Sass provides color functions for modifying and inspecting colors. The sass:color module offers functions for operations such as adjusting channels, changing color properties, mixing colors, and working with color spaces.
Color manipulation is useful when building related theme colors, hover states, muted borders, and accessible component palettes. However, a mathematically lighter color is not necessarily accessible against every background.
Always validate text contrast and visual state distinctions. For production design systems, explicitly defined semantic tokens are often easier to audit than a large number of implicit color transformations.
@use "sass:color";
$brand: #5b5bd6;
$brand-hover: color.adjust($brand, $lightness: -8%);
$brand-soft: color.mix(white, $brand, 85%);
.button {
background: $brand;
&:hover {
background: $brand-hover;
}
}
.badge {
color: $brand;
background: $brand-soft;
}color.adjust() changes the selected color property, while color.mix() blends two colors.
The generated colors should be tested against the intended text and background combinations. For accessible interfaces, verify contrast ratios and do not rely on color alone to communicate state.Why should generated color variations still undergo accessibility testing?