Dark mode colors that pass contrast
A gray label that looks fine on a white card can fade into the dark version. A dark brand button can disappear into the same card. Starting from #164e63, you can keep a deep blue button with white text in light mode and use a lighter blue with black text in dark mode. You can compare both modes in the theme generator.
npm install colore-js
yarn add colore-js
Measure the pair that fails
Try contrastRatio on a muted gray label against your dark background. Here, it gives 3.69:1, below the 4.5:1 target for normal text at WCAG AA. If a label sits on a card, use the card's background for this check.
import { contrastRatio } from 'colore-js/fn';
console.log(contrastRatio('#6b7280', '#0f172a').toFixed(2));
// 3.69
A card can be lighter than the page in dark mode, which shrinks the gap between the surface and muted text. Make a short list of the pairs you need before picking colors. For a settings page that might include the section title, the helper label and the action button.
Give each mode its own colors
generateSystem builds page, surface, text and action colors from the same brand. The primary button can change shade and foreground between modes. Keep them together, the way you keep muted text with the card it sits on.
import { generateSystem } from 'colore-js';
const system = generateSystem('#164e63', { level: 'aa' });
for (const mode of ['light', 'dark']) {
const { primaryBase, onPrimary } = system.theme(mode);
console.log(mode, primaryBase.hex(), onPrimary.hex());
}
light #164e63 #ffffff
dark #60a2bf #000000
Export CSS and check the colors you use
Save this complete example as generate-theme.mjs. It exports CSS to stdout and prints three text checks for each mode to stderr. These checks use the exact hex values written by .toCSS().
import { generateSystem } from 'colore-js';
import { contrastRatio } from 'colore-js/fn';
const system = generateSystem('#164e63', { level: 'aa' });
for (const mode of ['light', 'dark']) {
const theme = system.theme(mode);
const pairs = [
[theme.text, theme.background],
[theme.textSubtle, theme.surface],
[theme.onPrimary, theme.primaryBase],
];
const ratios = pairs.map(([text, bg]) => contrastRatio(text.hex(), bg.hex()).toFixed(2));
console.error(`${mode}: ${ratios.join(', ')}`);
}
const css = system.toCSS({ format: 'hex', darkSelector: '[data-theme="dark"]' });
process.stdout.write(css + '\n');
node generate-theme.mjs > theme.css
light: 19.23, 4.55, 9.11
dark: 20.14, 4.56, 7.42
Load theme.css before the component styles that use its variables. The same classes work in both modes. Toggle data-theme="dark" on <html> in the app's theme switch to activate the dark declarations.
:root { color-scheme: light; }
[data-theme="dark"] { color-scheme: dark; }
body { background: var(--color-background); color: var(--color-text); }
.card { background: var(--color-surface); }
.card-label { color: var(--color-text-subtle); }
.primary-button { background: var(--color-primary-base); color: var(--color-on-primary); }
The color-scheme declarations tell the browser which appearance to use for native controls. The variable declarations set your own colors. To preview the full result, switch modes on a real page with a card and a button, since a swatch alone does not show the text over its surface. CSS color scheme
Use the same approach for actual hover and selected states. If you lower a label's opacity or add an overlay over the card, measure again with those colors in place.
What Colore checks for you
The system uses the selected text contrast target when choosing role foregrounds. It also checks whether the primary seed stands out against dark surfaces and can pick a different shade for dark mode. Your layout decides which tokens end up next to each other. Check the actual foreground and background whenever you create a new pair.