---
name: design-color-on-color
description: "Polish: apply in a polish or review pass on existing UI, not while first designing a page; a first build only needs the basics right. How to color a border, ring, outline, divider, hover state, secondary text or icon that sits on a solid, known background color: derive a lighter or darker shade of that same color instead of mixing in black or white or using black/white with opacity. Use whenever writing or reviewing color-mix(... black/white ...), rgb(0 0 0 / x), rgba(255,255,255,x), bg-black/5, text-white/60, border-white/10 or opacity on text, when styling tinted pills, badges, tags, chips or cards, when something looks gray, muddy or washed out, or when a ring or fringe looks wrong in dark mode."
---

# Color on color

**When:** polish. A first build can use the repo's existing color tokens; apply this in a polish or review pass, or whenever a tinted element looks gray or muddy.

When you know the color behind an element, shade that color. Don't blend toward black or white, and don't use black or white with transparency.

Black or white with opacity is the right tool only when the background is unknown or has many colors: a ring over an avatar or photo, a scrim over an image, a hairline over arbitrary artwork. There, a neutral translucent edge works on everything.

On a solid, known color (a tinted pill, a colored card, a badge, a button), black or white pulls the color toward gray. A white `#` at 62% opacity on a green pill reads as gray-green, not green. A border mixed 12% toward black looks dirty. A lighter or darker shade of the same hue keeps it clean and on-palette.

## How

Use CSS relative color syntax in OKLCH, so you change lightness and keep hue:

```css
/* Darker shade of the background (light mode), lighter shade (dark mode) */
border-color: oklch(from var(--bg) calc(l - 0.08) c h);
.dark & { border-color: oklch(from var(--bg) calc(l + 0.1) c h); }

/* Secondary text in the background's hue, at a fixed lightness, opaque */
color: oklch(from var(--bg) 0.5 calc(c * 3) h / 1);
```

- Prefer a fixed lightness (`0.5`) for text so contrast holds whatever the background's lightness. Prefer a relative offset (`calc(l - 0.08)`) for borders and hover states that should stay close to the surface.
- Pastel or very dark backgrounds carry little chroma. When the shade should read as the color, multiply chroma (`calc(c * 3)`). Grays have no chroma, so they stay gray.
- Add `/ 1` when the source color might be translucent and the result must be opaque.
- `color-mix(in oklch, var(--bg), black 10%)` is the same anti-pattern in another form: it still mixes toward black.

## Check

Render it in light and dark mode on several hues (green, blue, orange, purple, gray) and compare the result with the old version at 2x. The shade should clearly look like the background's own color, and gray backgrounds should still look neutral.

## Related gotcha: rings over images

A 1px `outline` with a negative offset drawn over an image's rounded corner anti-aliases on the same pixels as the image edge, so light artwork leaks through as a thin fringe outside the ring. Use a `border` (the image is drawn inside it) when the ring color is solid. Chrome rounds outline widths down to whole pixels, so `outline-width: 1.5px` does not help.
