CKTIS / CSS
rgb() — direct red, green, and blue components
`rgb()` and its compatibility alias `rgba()` specify a color in `sRGB` with three channels and optional alpha.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
rgb( [ <number> | <percentage> | none ]{3} [ / [ <alpha-value> | none ] ]? ) | rgb( <legacy-rgb-syntax> )rgb() and its compatibility alias rgba() specify a color in sRGB with three channels and optional alpha.
rgb(300 -10 128 / 50%) computes to rgba(255, 0, 128, 0.5), and its transparent canvas pixel is 255,0,128,128. Modern unit mixing rgb(100% 0 128 / 50%) returns true, comma form rgb(100%, 0, 0%) returns false, and missing-component form rgb(none 0 0) is supported true.
Grammar: rgb( [ <number> | <percentage> | none ]{3} [ / [ <alpha-value> | none ] ]? ) | rgb( <legacy-rgb-syntax> ).
Modern rgb(100% 0 128 / 50%) separates channels with spaces and alpha with /; legacy rgb(255, 0, 128) uses commas. Modern syntax can mix numbers and percentages and accepts none; legacy syntax requires one channel type and forbids none. Number 255 and percentage 100% are channel maxima, omitted alpha is opaque, and out-of-range values clamp at parsed-value time.
Examples
const value='rgb(300 -10 128 / 50%)';
const probe=document.createElement('div');probe.style.backgroundColor=value;document.body.append(probe);
const canvas=document.createElement('canvas');canvas.width=canvas.height=1;const context=canvas.getContext('2d');context.clearRect(0,0,1,1);context.fillStyle=value;context.fillRect(0,0,1,1);
const pixel=[...context.getImageData(0,0,1,1).data].join(',');
const modernMixed=CSS.supports('color','rgb(100% 0 128 / 50%)');
const legacyMixed=CSS.supports('color','rgb(100%, 0, 0%)');
const missing=CSS.supports('color','rgb(none 0 0)');
console.log('computed='+getComputedStyle(probe).backgroundColor+'; pixel='+pixel+'; modern-mixed='+modernMixed+'; legacy-mixed='+legacyMixed+'; none='+missing);Result
computed=rgba(255, 0, 128, 0.5); pixel=255,0,128,128; modern-mixed=true; legacy-mixed=false; none=true
`rgb()` and its compatibility alias `rgba()` specify a color in `sRGB` with three channels and optional alpha.