Red plus blue gives purple, but CSS has no simple way to say that. A color-mix function exists only as a draft in CSS Color 5, and although Chrome has shown some interest in it, native color mixing is not imminent. Such a feature would let designers build tinted variants of a base color into a palette. Until then, the effect has to be assembled from existing CSS mechanisms.
Working around the missing function
CSS offers calc() for arithmetic on numbers, but almost nothing for operating on colors directly — even though formats like hsl() and rgb() are built on numeric channels. The route that does work is animation: colors can be transitioned, and the intermediate value of a running animation is itself a color.
div {
background: blue;
transition: 0.2s;
}
div:hover {
background: red;
}
The same behavior under a keyframe animation:
div {
background: blue;
transition: 0.2s;
}
div:hover {
animation: change-color 0.2s forwards;
}
@keyframes change-color {
to {
background: red;
}
}
That animation loops infinitely between red and blue. With the console open and the page clicked, JavaScript can report the exact color at whatever point the animation has reached.
Pausing the animation at a chosen point
The useful part is stopping the animation mid-flight. An animation-delay of -0.5s on a 1s animation holds it exactly halfway through, which yields the color halfway between red and blue: purple. Changing that negative delay therefore selects the percentage between the two endpoint colors.
Chromium-based browsers and Firefox handle this. In Safari, the animation-name must be changed so the browser recalculates the animation's progress.
The trick also covers the alpha channel, which is commonly needed when mixing colors for theming.
Exposing the mix through a custom property
Driving an animation on every element that needs a mixed color is impractical, and it confines the result to whatever is set inside the @keyframes. Two additions make the approach more usable:
- An
@propertytyped custom property, registered as a proper color so it can be animated as a color. - A Sass
@functionthat calls the keyframes at a chosen point.
The animation still has to be invoked, but the mixed result lands in a custom property that any other property can then consume.



