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.
Practice
mix() function in Sass do?Solution
Step 1: Understand the purpose of
Themix()mix()function combines two colors into one by blending them.Step 2: Recognize the role of the weight parameter
The weight controls how much of each color is used in the blend, creating a new color.Final Answer:
It blends two colors into a new color based on a weight. -> Option DQuick Check:
mix() blends colors = It blends two colors into a new color based on a weight. [OK]
- Confusing mix() with gradient creation
- Thinking mix() changes opacity only
- Assuming mix() converts colors to grayscale
mix() in Sass?Solution
Step 1: Identify the correct parameter order
Themix()function takes two colors first, then the weight as a percentage.Step 2: Confirm the weight meaning
The weight is the percentage of the first color in the blend, so 70% means mostly red.Final Answer:
mix(red, blue, 70%) -> Option AQuick Check:
mix(color1, color2, weight%) = mix(red, blue, 70%) [OK]
- Swapping color order and weight
- Using decimal instead of percentage
- Adding named parameters incorrectly
mix(#ff0000, #0000ff, 50%) in Sass?Solution
Step 1: Understand the colors and weight
#ff0000 is red, #0000ff is blue, and 50% weight means equal parts.Step 2: Calculate the blend
mix() calculates the weighted average of RGB channels. For 50%, it averages red (255,0,0) and blue (0,0,255) to (127.5,0,127.5), which rounds to #7f007f (dark purple), not #800080.Step 3: Correct hex code
The actual result is #7f007f, which is dark purple, not #800080.Final Answer:
#7f007f (dark purple) -> Option CQuick Check:
mix(#ff0000, #0000ff, 50%) = #7f007f [OK]
- Confusing hex codes for purple shades
- Assuming pink or navy instead of purple
- Ignoring equal weight meaning
color: mix(red, blue 50%);
Solution
Step 1: Check the function syntax
Themix()function requires commas between arguments.Step 2: Spot the missing comma
Betweenblueand50%there is no comma, causing a syntax error.Final Answer:
Missing comma between blue and 50% -> Option AQuick Check:
Arguments must be comma-separated [OK]
- Omitting commas between parameters
- Using decimal instead of percentage incorrectly
- Thinking color keywords are invalid
mix(). Which code snippet achieves this correctly?Solution
Step 1: Understand weight meaning in mix()
The weight is the percentage of the first color in the blend.Step 2: Match desired color proportions
To get 30% green and 70% yellow, yellow must be first with 70% weight.Final Answer:
background-color: mix(yellow, green, 70%); -> Option BQuick Check:
Weight = first color percent [OK]
- Swapping colors and weights
- Assuming weight is second color percent
- Using wrong percentage values
Ready to prove it?
Pass the test and this pattern moves unknown
