The mix() function helps you blend two colors together. It creates a new color that is a mix of both, making your designs smooth and balanced.
Mix function for blending in SASS
mix($color1, $color2, [$weight])
$color1 and $color2 are the two colors you want to blend.
$weight is optional and controls how much of $color1 is in the mix. It is a percentage from 0% to 100%. Default is 50%.
mix(red, blue)
mix(red, blue, 25%)mix(#ff0000, #0000ff, 75%)
This example blends red and blue equally to create a purple color. The purple color is used as the background of a square box with text inside. The box is centered and styled for clear visibility.
@use 'sass:color'; $color1: #ff0000; // bright red $color2: #0000ff; // bright blue $blended-color: color.mix($color1, $color2, 50%); .my-box { width: 10rem; height: 10rem; background-color: $blended-color; border: 0.2rem solid black; display: flex; justify-content: center; align-items: center; color: white; font-weight: bold; font-family: sans-serif; } // HTML part: // <div class="my-box">Mixed Color</div>
The mix() function works best with colors in any CSS-supported format (named colors, hex, rgb, hsl).
If you omit the $weight, it defaults to 50%, mixing colors evenly.
Use browser DevTools to inspect the resulting color and tweak the $weight for perfect blending.
mix() blends two colors into one new color.
You can control how much of each color appears using the $weight parameter.
This helps create smooth color transitions and consistent design palettes.