Color-mix computes a color from input colors in a named color space and chosen proportions. Its result depends on the color space as well as the weights, so the same inputs can look different in different spaces.
CSS color-mix: derive a surface without assuming contrast
When to use it
A reconciliation panel uses a mild highlight based on its brand accent. Define a solid fallback first, then mix the accent with white for the panel background in supporting browsers. Keep the text color explicit. The sample uses sRGB for a predictable compatibility choice; a perceptual space can produce a different visual result and needs its own review. Do not infer that a 15-percent accent automatically passes contrast with dark text. Test the final computed color against the real font size and weight, in dark mode, and in forced colors. If a custom property supplies the accent, inspect its fallback too. A missing token can invalidate the computed declaration even when color-mix itself is supported.
.reconciliation-panel { color: #173148; background: #e9f1f3; }
@supports (color: color-mix(in srgb, #24778a, white)) { .reconciliation-panel { background: color-mix(in srgb, #24778a 15%, white); } }Cost and verification
Color calculation is cheap relative to image transfer or animation. The real cost is theme testing across every combination that can feed the mix. Alpha, color space, and percentages all influence the final pixel color. Use an automated contrast check on the computed result and confirm it visually under real rendering. A fallback belongs before the enhanced declaration in the same cascade position. Do not use a mixed warning background as the only signal of an error; keep the status in text and preserve a distinct border or icon where appropriate.
Common Mistakes
- Do not assume a percentage guarantees accessible contrast.
- Do not omit a solid fallback for older clients.
- Do not let an undefined custom property silently remove the background declaration.
