CSS Color Mix Function

Blend colors dynamically using CSS color-mix function for creating tints shades and opacity variants at runtime.

CssConfig Management

Code

:root { --brand: #4f46e5; }

.button {
  background: var(--brand);
  border: 2px solid color-mix(in srgb, var(--brand) 80%, black);
}

.hover-bg {
  background: color-mix(in srgb, var(--brand) 90%, white);
}

CSS Color Mix Function

Blend colors dynamically using CSS color-mix function for creating tints shades and opacity variants at runtime.

Code

:root { --brand: #4f46e5; }

.button {
  background: var(--brand);
  border: 2px solid color-mix(in srgb, var(--brand) 80%, black);
}

.hover-bg {
  background: color-mix(in srgb, var(--brand) 90%, white);
}

Explanation

color-mix() blends two colors in a chosen color space at runtime, so a tint can be derived from a base token instead of hard-coded. Expected behavior: the result is an ordinary color that can be used anywhere a color is accepted. Caveat: the perceptual result depends on the interpolation space (srgb versus oklab), so identical percentages can look different across spaces.

Interactive Tools for This Topic