Sass
CSS preprocessor

Sass color.mix() Function

Beginner
⏱️ 14 min read
📚 Updated: Jul 2026
🎯 5 Examples
sass:color · Dart Sass

What You’ll Learn

color.mix() belongs to the built-in sass:color module. It blends two colors at compile time. This page covers $weight, optional $method (Dart Sass 1.79+ / CSS color-mix() algorithm), the historical opacity-aware path, how it differs from CSS color-mix(), and five compiled examples.

01

Concept

Blend two colors

02

Module

@use "sass:color"

03

Weight

More of $color1

04

Method

Optional (1.79+)

05

Vs CSS

color-mix()

06

Practice

5 examples

What Is color.mix()?

Mix means “meet these two colors in the middle—or closer to one side.” Official docs return a color that is a mixture of $color1 and $color2. Design systems use it for hover tints, soft borders, and token ladders from a brand + a neutral.

  • color.mix(#036, #d2e1dd)#698aa2 (50% each)
  • color.mix(#036, #d2e1dd, 75%)#355f84 (more brand)
  • color.mix(#036, #d2e1dd, $weight: 25%)#9eb6bf (more tint)
💡
Beginner tip

Remember the weight direction: bigger weight = more of the first color. So 80% keeps most of $color1; 20% leans toward $color2.

📝 Syntax

Load the color module, then pass two colors, optional weight, and optional method:

styles.scss
@use "sass:color";

color.mix($color1, $color2, $weight: 50%, $method: null)
// Global alias:
// mix($color1, $color2, $weight: 50%, $method: null)

Parameters

ParameterTypeDescription
$color1ColorFirst color (required). With modern $method, the result is returned in this color’s space.
$color2ColorSecond color to blend with (required).
$weightPercentageHow much of $color1 to keep (0%–100%). Default 50%.
$methodSpace name (+ optional hue method)Interpolation method (Dart Sass 1.79+). Example: rgb, oklch, or oklch longer hue.

Return value

TypeMeaning
ColorA new color between $color1 and $color2, controlled by $weight (and $method when set).

📦 Loading sass:color

Prefer the module API. Official docs also document the global name mix() for older stylesheets.

styles.scss
// Recommended — namespaced
@use "sass:color";
$mid: color.mix(#036, #d2e1dd);

// Optional — bring members into the current namespace
@use "sass:color" as *;
$mid: mix(#036, #d2e1dd);

// Optional — custom namespace
@use "sass:color" as c;
$mid: c.mix(#036, #d2e1dd);

// Legacy global name
$mid: mix(#036, #d2e1dd);
⚠️
Put @use first

Keep @use "sass:color"; near the top of the file. Built-in modules need Dart Sass (about 1.23+). Passing $method needs 1.79+. Prefer color.mix() so it never looks like CSS color-mix().

⚖️ How $weight Works

Official docs: the weight must be between 0% and 100% (inclusive). A larger weight means more of $color1; a smaller weight means more of $color2.

WeightFeels like
100%Almost entirely $color1
50% (default)Even blend of both
0%Almost entirely $color2

🎨 $method and CSS color-mix() Math

On Dart Sass 1.79+, pass $method as a color space name—and for polar spaces (hsl, hwb, lch, oklch) you may add a hue interpolation method such as longer hue. Official docs: this uses the same algorithm as CSS color-mix().

  • Missing channels in the interpolation space take the other color’s corresponding channel.
  • The result is always returned in $color1’s color space.
  • Example: color.mix(#036, #d2e1dd, $method: rgb)#698aa2
  • Example: color.mix(#036, #d2e1dd, $method: oklch) produces a different midtone than RGB mixing.
⚠️
Heads up from the docs

For historical reasons, $method is optional when both colors are in legacy spaces. Then Sass uses its older algorithm, where weight and relative opacity decide how much of each color appears in the result.

📋 Sass color.mix() vs CSS color-mix()

Both blend colors, but they run at different stages of the pipeline.

Sass color.mix()CSS color-mix()
When it runsCompile time (SCSS → CSS)In the browser
What CSS receivesA finished color (hex/rgb/…)The color-mix() function itself
Best forDesign tokens, fixed palette stepsDynamic themes, runtime interpolation
Modern space control$method (Dart Sass 1.79+)First argument space (e.g. in oklch)

🛠 Compatibility

This is about Sass compilers, not browsers. Compiled CSS receives a finished color—no color.mix() call remains (unless you intentionally write CSS color-mix() yourself).

FeatureDart SassNotes
@use "sass:color" / color.mix1.23+Preferred module API
$weight + legacy mixLong-standingOpacity-aware when $method is omitted on legacy colors
$method (CSS algorithm)1.79+Matches CSS color-mix(); required for non-legacy spaces
Global mix()Long-standingPrefer module form in new SCSS
LibSass / Ruby SassNo modern module APIMay expose global mix(); prefer Dart Sass

⚡ Quick Reference

GoalCode
Import color@use "sass:color";
Even blendcolor.mix(#036, #d2e1dd)
More of first colorcolor.mix($a, $b, 75%)
More of second colorcolor.mix($a, $b, $weight: 25%)
RGB method (1.79+)color.mix($a, $b, $method: rgb)
Oklch method (1.79+)color.mix($a, $b, $method: oklch)
Hue path (1.79+)color.mix($a, $b, $method: oklch longer hue)
CSS runtime mix (different)color-mix(in srgb, #036 50%, #d2e1dd)
Legacy globalmix(#036, #d2e1dd)

Examples Gallery

Examples 1–3 and 5 compile on everyday Dart Sass. Example 4 shows official $method results for Dart Sass 1.79+. Open View Compiled CSS to inspect the output.

📚 Getting Started

Even blends, weight ladders, and opacity-aware historical mixes.

Example 1 — Even Blend of Two Brand Colors

Default 50% mix (classic docs pair: deep blue + mint).

styles.scss
@use "sass:color";

@debug color.mix(#036, #d2e1dd); // #698aa2

.swatches {
  color: color.mix(#036, #d2e1dd);
  background: color.mix(#036, white, 15%);
}

How It Works

With no weight argument, Sass uses 50%. Mixing the brand with white at 15% keeps a soft wash that still feels related to #036.

Example 2 — Weight Ladder for Hover States

Push toward the brand or toward the tint for interactive steps.

styles.scss
@use "sass:color";

$brand: #036;
$tint: #d2e1dd;

.palette {
  --mid: #{color.mix($brand, $tint)};
  --more-brand: #{color.mix($brand, $tint, 80%)};
  --more-tint: #{color.mix($brand, $tint, 20%)};
}

.button:hover {
  background: color.mix($brand, $tint, 65%);
}

How It Works

80% stays close to the brand; 20% drifts toward the mint tint. Hover at 65% is a practical mid-dark step without inventing a new hex by hand.

📈 Practical Patterns

Opacity-aware history, modern $method, and CSS color-mix contrast.

Example 3 — Historical Mix Respects Opacity

Without $method, relative opacity also shapes the blend.

styles.scss
@use "sass:color";

.overlay {
  // Half-opaque cream mixed with solid slate
  background: color.mix(rgba(242, 236, 228, 0.5), #6b717f);
}

How It Works

Official docs note that the historical algorithm factors in each color’s opacity. The cream is only 50% opaque, so the result is a translucent gray—not a fully opaque midtone.

Example 4 — $method: RGB vs Oklch (Dart Sass 1.79+)

Same two hexes, different interpolation spaces (official docs samples).

styles.scss
@use "sass:color";

// Requires Dart Sass 1.79+
@debug color.mix(#036, #d2e1dd, $method: rgb);   // #698aa2
@debug color.mix(#036, #d2e1dd, $method: oklch); // modern midtone

.methods {
  --rgb: #{color.mix(#036, #d2e1dd, $method: rgb)};
  --oklch: #{color.mix(#036, #d2e1dd, $method: oklch)};
}

.polar {
  // Hue interpolation method on a polar space
  color: color.mix(
    oklch(80% 20% 0deg),
    oklch(50% 10% 120deg),
    $method: oklch longer hue
  );
}

How It Works

RGB mixing lands on the familiar #698aa2. Oklch mixing follows perceptual space math (like CSS color-mix()). longer hue picks the long way around the hue circle when blending polar colors.

Example 5 — Sass Mix vs CSS color-mix() + Global Alias

Compile-time tokens next to a runtime CSS mix; module and global names match.

styles.scss
@use "sass:color";

.chip {
  // Sass: finished color in the CSS file
  color: color.mix(#036, #d2e1dd);
  --module: #{color.mix(#036, #d2e1dd)};
  --global: #{mix(#036, #d2e1dd)};
}

.chip.is-live {
  // CSS: browser blends at paint time (not a Sass helper)
  background: color-mix(in srgb, #036 50%, #d2e1dd);
}

How It Works

Module and global Sass mixes compile to the same hex. The CSS color-mix() declaration is left for the browser—useful when a theme may change at runtime.

🚀 Real-World Use Cases

  • Hover / active tints — mix brand + surface for interactive states.
  • Border / divider softens — blend a strong accent toward white or gray.
  • Token ladders — generate 20% / 50% / 80% steps from two seed colors.
  • Overlay chips — historical opacity-aware mixes for translucent UI layers.
  • Perceptual midtones — use $method: oklch on Dart Sass 1.79+.
  • Teaching color math — compare Sass tokens with CSS color-mix().

🧠 How Compilation Works

1

Write SCSS

Call color.mix($c1, $c2, ...) after @use.

Source
2

Pick the algorithm

Use $method (1.79+) or the historical legacy mix.

Method
3

Apply weight

Bias toward $color1 or $color2 with $weight.

Blend
4

Plain CSS color ships

Browsers receive hex/rgb/oklch—not a Sass call.

⚠️ Common Pitfalls

  • Reversing weight — bigger % means more of $color1, not more of $color2.
  • Confusing CSS color-mix() — runtime CSS syntax is not the Sass helper.
  • Using $method on older Dart Sass — needs 1.79+; bare color.mix($a, $b) still works earlier on legacy colors.
  • Ignoring opacity — historical mixes factor transparency into the result.
  • Expecting the same midtone in every spacergb and oklch methods can disagree.

💡 Best Practices

✅ Do

  • Use @use "sass:color" and color.mix() in new SCSS
  • Name tokens by intent ($hover, $border-soft)
  • Pass $method explicitly on Dart Sass 1.79+ when space matters
  • Keep CSS color-mix() for true runtime themes
  • Check contrast after mixing text and backgrounds

❌ Don’t

  • Expect the browser to re-run color.mix
  • Guess weight direction—test a ladder (20 / 50 / 80)
  • Assume RGB and oklch midtones match
  • Rely on LibSass for sass:color
  • Skip accessibility checks on mixed UI colors

Key Takeaways

Knowledge Unlocked

Five things to remember about color.mix()

Compile-time blends—tune with weight, choose a method on 1.79+.

5
Core concepts
📦 02

Module

sass:color

@use
🎨 03

Does

blend two colors

Mix
04

Weight

more of $color1

Bias
05

Not CSS

color-mix()

Different

❓ Frequently Asked Questions

color.mix($color1, $color2, $weight: 50%, $method: null) returns a color that is a mixture of the two inputs. Example: color.mix(#036, #d2e1dd) is #698aa2.
Weight must be between 0% and 100%. A larger weight uses more of $color1; a smaller weight uses more of $color2. Default is 50% (an even blend).
On Dart Sass 1.79+, $method is a color space name (optionally with a hue interpolation method for hsl, hwb, lch, or oklch). Sass then mixes with the same algorithm as CSS color-mix(). Example: color.mix(#036, #d2e1dd, $method: oklch).
Same idea, different stage. Sass color.mix() runs at compile time and writes a finished color into CSS. CSS color-mix() runs in the browser. Prefer Sass when the blend must be fixed in the stylesheet.
Add @use "sass:color"; then call color.mix($a, $b) or color.mix($a, $b, 75%). Prefer the module form. The global alias is mix().
The module form needs Dart Sass with @use (about 1.23+). The $method argument needs Dart Sass 1.79+. LibSass/Ruby Sass may expose a global mix() but lack the modern module and $method API.
Did you know?

Official Sass docs show that with $method, a missing channel in one color borrows the matching channel from the other—just like CSS color-mix(). That is why mixing color(rec2020 0.8 none 0.3) with a full rec2020 color can fill in the missing channel instead of treating it as zero.

Conclusion

color.mix() is the clearest way to ask Sass for a two-color blend. Use $weight to bias the mix, pass $method on Dart Sass 1.79+ when you want CSS color-mix() math, and keep runtime color-mix() for live themes.

Continue with color.same(), color.adjust(), or the CSS introduction.

Explore color.same() Next

Compare visual color equality across spaces with the sass:color module (Dart Sass 1.79+).

Sass color.same() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful