CSS color-mix for Tinted Surfaces
Lesson 30 of 41 in the CSS3 learning path.
How do I tint a surface with a brand color without a preprocessor?
color-mix blends two colors in a given space. A 12 percent blue mixed into white is a tint you can use for a card background.
You keep one brand token and derive the quiet surfaces from it. You do not invent a second hex by eye.
Syntax & Parameters
background: color-mix(in srgb, #1d4ed8 12%, white);
Example
Interactive preview available:root {
--brand: #1d4ed8;
}
.card {
background: color-mix(in srgb, var(--brand) 12%, white);
color: #0f172a;
border: 1px solid color-mix(in srgb, var(--brand) 35%, white);
padding: 1rem;
border-radius: 12px;
}
.card strong {
color: var(--brand);
}
Expected Output
A pale blue card with a slightly stronger blue border and a solid blue emphasis word.
Line-by-Line Walkthrough
- The brand token lives on :root.
- The card background mixes 12 percent brand into white.
- The border uses a stronger 35 percent mix.
- The body text stays a dark slate so it is not also mixed.
- The strong word uses the pure brand color.
- srgb is the color space for this mix.
- Changing --brand retints every card.
- Do not mix text into white if the result fails contrast.
Common Pitfalls & Security
Watch the failure mode, not only the happy path.
- Mixing body text the same way as the background can fail contrast.
- The property is ignored by old browsers, so set a solid fallback first.
- in srgb and in oklch do not produce the same tint.
- A 50 percent mix is not automatically an accessible border.
Best Practices & Modern Standards
Declare the brand once. Derive tints with color-mix.
Put a solid background before the mix so older browsers still show a surface.
Real-World Use
Every course card uses the same blue token. Track pages only change the token, and the tinted background follows.
Frequently Asked Questions
Do I still need a hex for the tint?
No. The mix is the tint. Keep the hex for the brand token only.
Which space should I use?
srgb matches how most UI colors were chosen. oklch is more even but looks different.
Can I mix with a variable?
Yes. var(--brand) works as either color.
Does it replace opacity?
Opacity fades the whole element, including text. color-mix tints only the color you name.