螢幕發光體採用 RGB 加色模型:紅(R)、綠(G)、藍(B) 三原光疊加產生顏色。
| 函數 | 語法 | 特色 |
|---|---|---|
| rgb() / rgba() | rgb(255 0 0 / 50%) | 空格分隔、斜線分隔 alpha、支援百分比 |
| hsl() / hsla() | hsl(0 100% 50% / 0.5) | 直覺調色、同樣支援空格/斜線語法 |
| hwb() | hwb(0 0% 0%) | 色相+白度+黑度,更符合人類直覺 |
| lab() / lch() | lab(53.23% 104.55 40.5) / lch(53.23% 104.55 40.5) | 感知均勻色彩空間,漸變更自然 |
| color() | color(display-p3 1 0 0) | 指定色域 (sRGB, display-p3, a98-rgb, prophoto-rgb, rec2020) |
| color-mix() | color-mix(in srgb, blue 30%, white) | 在指定色空間混合兩色 |
| relative color syntax | rgb(from var(--c) r g b / 0.5) | 從現有色值衍生新色 (CSS Color Level 5) |
.gradient-srgb { background: linear-gradient(to right, red, white); }
.gradient-lab { background: linear-gradient(in lab, red, white); }
.gradient-lch { background: linear-gradient(in lch, red, white); }
.gradient-hsl { background: linear-gradient(in hsl longer hue, red, white); }
不同色彩空間插值視覺差異巨大:sRGB 會出現灰暗中間帶,LCH/Lab 能保持飽和度,HSL 可控制色相插值方向 (shorter/longer/increasing/decreasing)。
@media (color-gamut: p3) 偵測裝置支援 P3 色域。color: color(display-p3 1 0 0); 定義 P3 純紅(比 sRGB 紅更飽和)。<picture> + type="image/avif" 等新格式。