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);
}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
CSS Color Name LookupTranslate between CSS keyword color names and hex values with RGB and HSL conversions, exact name matching, and nearest-color suggestions.Tailwind Color Palette GeneratorGenerate a balanced 50-950 Tailwind CSS custom property color scale from any hex, RGB, or HSL base color with WCAG 2.1 contrast ratios for every stop.CSS Color ConverterConvert colors between HEX, rgb(), and hsl() instantly, with support for shorthand hex and rgb or hsl inputs. Fully offline and dependency free.RGBA / Hex Color ConverterConvert colors between #RRGGBB, #RRGGBBAA, rgb(), and rgba() forms with alpha handling and validation.
Report a problem with this exampleOpens a pre-filled issue on GitHub.