CKTIS / CSS
color-mix() — mixing in a chosen color space
`color-mix()` interpolates a list of colors in an explicit color space using supplied percentage weights, returning a CSS color.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
color-mix( <color-interpolation-method>? , [ <color> && <percentage [0,100]>? ]# )color-mix() interpolates a list of colors in an explicit color space using supplied percentage weights, returning a CSS color.
The example evaluates color-mix(in srgb, rgb(255 0 0) 20%, rgb(0 0 255) 40%). The weights normalize to a 1:2 ratio, but their 60% total multiplies alpha, so the result is color(srgb 0.333333 0 0.666667 / 0.6) and compositing over white yields 153,102,204.
Grammar: color-mix( <color-interpolation-method>? , [ <color> && <percentage [0,100]>? ]# ).
An omitted interpolation method means oklab. Weights must be between 0% and 100%; negative weights are forbidden. Omitted weights share the remainder, a total above 100% is normalized without extra transparency, and a total below 100% additionally multiplies alpha by that total. A zero total produces fully transparent color; the space and hue-interpolation method can visibly change the result.
Examples
const swatch=document.createElement('div');document.body.append(swatch);swatch.style.backgroundColor='color-mix(in srgb, rgb(255 0 0) 20%, rgb(0 0 255) 40%)';const computed=getComputedStyle(swatch).backgroundColor;const canvas=document.createElement('canvas');canvas.width=canvas.height=1;const context=canvas.getContext('2d');context.fillStyle='white';context.fillRect(0,0,1,1);context.fillStyle=computed;context.fillRect(0,0,1,1);const pixel=[...context.getImageData(0,0,1,1).data].slice(0,3);if(computed!=='color(srgb 0.333333 0 0.666667 / 0.6)'||pixel.join(',')!=='153,102,204')throw new Error('color-mix weight/alpha evidence mismatch: '+[computed,pixel]);console.log('computed='+computed+'; over-white='+pixel.join(','));Result
computed=color(srgb 0.333333 0 0.666667 / 0.6); over-white=153,102,204
`color-mix()` interpolates a list of colors in an explicit color space using supplied percentage weights, returning a CSS color.