CKTIS / CSS
color() — color in an explicit space
`color()` writes a color in a named color space, supplying that space’s components and an optional slash-separated alpha.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
color( [ from <color> ]? <colorspace-params> [ / [ <alpha-value> | none ] ]? )color() writes a color in a named color space, supplying that space’s components and an optional slash-separated alpha.
The example renders color(srgb 0.2 0.4 0.6 / 0.5) over white and obtains pixel 153,178,204. The value color(srgb none 0.4 0.6 / none) preserves missing components in the computed value; during direct painting its missing alpha becomes zero, so white shows through as 255,255,255.
Grammar: color( [ from <color> ]? <colorspace-params> [ / [ <alpha-value> | none ] ]? ).
Predefined spaces such as srgb and display-p3 require three components; numbers refer to the nominal range from 0 to 1. Out-of-gamut components do not invalidate a color but are gamut-mapped. none marks a missing component: during interpolation it can be carried from the other color’s analogous component, while outside interpolation it is replaced by zero. Omitted alpha defaults to 100%.
Examples
const paint=value=>{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=value;context.fillRect(0,0,1,1);return [...context.getImageData(0,0,1,1).data].slice(0,3)};const swatch=document.createElement('div'),missing=document.createElement('div');document.body.append(swatch,missing);swatch.style.backgroundColor='color(srgb .2 .4 .6 / .5)';missing.style.backgroundColor='color(srgb none .4 .6 / none)';const computed=getComputedStyle(swatch).backgroundColor,missingComputed=getComputedStyle(missing).backgroundColor,composite=paint(computed),missingPixel=paint(missingComputed);if(computed!=='color(srgb 0.2 0.4 0.6 / 0.5)'||composite.join(',')!=='153,178,204'||missingComputed!=='color(srgb none 0.4 0.6 / none)'||missingPixel.join(',')!=='255,255,255')throw new Error('color() channel/alpha evidence mismatch: '+[computed,composite,missingComputed,missingPixel]);console.log('computed='+computed+'; composite='+composite.join(',')+'; missing='+missingComputed+'; missing-over-white='+missingPixel.join(','));Result
computed=color(srgb 0.2 0.4 0.6 / 0.5); composite=153,178,204; missing=color(srgb none 0.4 0.6 / none); missing-over-white=255,255,255
`color()` writes a color in a named color space, supplying that space’s components and an optional slash-separated alpha.