Keep theme colors attached to roles
A visual guide to mapping color roles across light and dark themes, with real browser captures, measured button-label contrast and a small CSS pattern.

A light theme can hide a weak color model. The same blue may look convincing on a button, an inline link and a selected card. When the interface turns dark, you brighten that blue—and the white button label becomes difficult to read. The value was shared, but the jobs were different.
For a small interface, start by naming the jobs you need: page canvas, card surface, main text, secondary text, action fill and text on that action. Keep those names in the component. Give each theme its own values, then review the pairs that actually touch.
Give a color a specific job
Carbon’s color guidance describes tokens whose names and roles remain stable across themes while their assigned values change. That gives a useful review question: can you describe the purpose of this color without mentioning its current shade? “Secondary text” answers that question. “Gray 500” only identifies a palette value.
In this reading board, the card stays visually distinct from the page in both themes. Its title remains the strongest text; the description is quieter; the save action remains easy to find. These relationships are the design. A theme is successful when it carries them into another palette without forcing every component to invent exceptions.
Real local demo capture, light theme. The card, secondary text and focused save action each have a separate role.Two ways to connect a component to color
Choose a shade
The component asks for a palette value directly.
- A shared blue may serve links, fills and outlines.
- A later shade change can affect unrelated uses.
- Local overrides become harder to explain.
Choose a role
The component asks for the color’s purpose.
- Action fill and action label have separate names.
- Each theme defines a deliberate pair.
- A palette change has a visible scope to review.
A palette can still be useful underneath these roles. The important part is the component’s dependency: a button should request its action colors rather than guess which numbered blue happens to work today. Keep the vocabulary small enough that another person can choose the right token without reading the whole stylesheet.
Map the label together with the fill
Real local demo capture. Both fills are #a5b4fc. The fixed #ffffff label computes to about 1.99:1; the #172033 label computes to about 8.16:1.The original light pair is white on #354fc4, about 6.85:1. In the dark theme, the action fill changes to #a5b4fc. Keeping white for its label produces about 1.99:1; mapping the label to #172033 produces about 8.16:1. These are calculations from the demo’s opaque computed CSS colors, using sRGB relative luminance—not a judgment from screenshot pixels.
W3C’s contrast guidance sets a 4.5:1 threshold for normal text, with stated exceptions including large text. It also warns against rounding a value up to pass. The rounded ratios here explain this example; the check used the unrounded values. A readable button label does not establish that the entire interface meets accessibility requirements.
The demo’s theme values| Role | Light | Dark |
|---|
| Canvas | #f4f2ed | #111827 |
| Surface | #ffffff | #1f2937 |
| Text | #172033 | #f3f4f6 |
| Secondary | #526071 | #b9c3d1 |
| Action | #354fc4 | #a5b4fc |
| On action | #ffffff | #172033 |
Review each pair where it is used. Secondary text sits on a surface; an action label sits on a fill; a focus indicator meets the surrounding area. Reusing a value is reasonable when the roles happen to agree. Giving the roles distinct names leaves room for them to diverge later.
Let CSS select the theme values
For color pairs, light-dark() selects its first or second value according to the used color scheme. Declare support for both schemes, then keep the selection in the role definitions. The component rules below do not need their own dark-mode branch.
:root {
color-scheme: light dark;
--action: light-dark(
#354fc4, #a5b4fc
);
--on-action: light-dark(
#ffffff, #172033
);
}
.save-button {
background: var(--action);
color: var(--on-action);
}
:root[data-theme="light"] {
color-scheme: light;
}
:root[data-theme="dark"] {
color-scheme: dark;
}
The color-scheme property also informs browser-provided UI such as form controls and scrollbars. It does not invent a complete palette for your custom card. Define those colors yourself. In the demo, choosing System lets the browser preference decide; choosing Light or Dark sets the root attribute shown above. Returning to System removes that explicit scheme choice.
Treat this CSS as a focused excerpt. A production theme control also needs an accessible label, a clear current choice and a decision about persistence. Check light-dark() against your supported browser versions; if older clients are required, provide a tested alternative mapping rather than assume the function is available.
Real local demo capture, dark theme. The content and layout stay the same. The paired action colors and visible keyboard focus survive the theme change.Review a theme as a set of states
The study was exercised at 520, 390 and 320 CSS pixels. The save action worked by keyboard, both explicit themes stayed within the viewport, and the System setting followed emulated light and dark preferences. Those are bounded observations of this fixture. They do not replace checking your own components, browsers and content.
A practical theme review
List the roles
Start with one real card and name its surfaces, text, action fill and action label. Keep the existing layout and content.
Map both palettes
Choose values for each role in each theme. Make a foreground/background pair explicit before measuring it.
Exercise the states
Inspect hover, keyboard focus, selection, errors and disabled controls in both themes. Add a role when the state needs an independent decision.
Try real content
Use long labels, small secondary text and narrow screens. Check images and charts separately; a theme token does not recolor every asset.
When handing this to another designer or an AI editor, name the role to change and the pairs to preserve: “Adjust the dark action fill and its label together; keep the page structure and review focus at phone width.” That brief gives the next edit a concrete target and leaves a useful trail for review.
Back to the LOOKFILE blog