Skip to content

Dark Mode Override

Wrap your dark-theme token overrides in a prefers-color-scheme: dark media query — the light theme is completely untouched.

Many sites switch to a dark UI at night or when the OS dark mode is active. This recipe makes the Kookiok banner follow suit: on light mode it shows the default (or your custom light) palette; on dark mode it switches to a deep background with appropriately contrasted text and buttons — all without any JavaScript.

custom.css
/* ── Dark mode colour overrides ────────────────────────── */
@media (prefers-color-scheme: dark) {
.ag-banner {
/* Background surface */
--surface: #1e2030;
/* Text on surface */
--surface-text: #e2e8f0;
/* Subtle secondary text (legal links, descriptions) */
--surface-text-muted: #94a3b8;
/* Primary accent — buttons, focus rings, ticks */
--accent: #818cf8; /* indigo-400: lighter for dark bg */
/* Button background */
--btn-fill: #4f46e5; /* indigo-600 */
/* Button text — must contrast with --btn-fill */
--btn-text: #ffffff;
/* Link / secondary action colour */
--link: #a5b4fc; /* indigo-300 */
/* Border / divider colour */
--border: #334155;
/* Shadow (lighter shadow on dark bg is less visible) */
--shadow: 0 4px 24px 0 rgba(0, 0, 0, 0.6);
}
}

The preview iframe renders in light mode by default because it runs in an isolated frame. The actual dark-mode switch will activate on a user’s device when their OS preference is dark.

classic · dialog · center
  • @media (prefers-color-scheme: dark) scopes every rule to dark-mode visitors only. The bracket is the entire override — anything outside is the light theme.
  • --surface and --surface-text are the two most important tokens. A dark surface needs a light foreground; here #1e2030 (near-black) pairs with #e2e8f0 (near-white slate).
  • --accent shifts from a saturated color to a lighter tint. Saturated hues (e.g. #4f46e5) look good on white but appear too dark on a dark surface; their light variants (#818cf8) maintain contrast.
  • --link: #a5b4fc — link text needs to be lighter still than the accent, to read clearly against the dark surface without a hover state.
  • --shadow is dialed up to rgba(0,0,0,0.6) because dark backgrounds absorb light shadows; a stronger value keeps the card elevated.

Dark amber / warm dark mode:

@media (prefers-color-scheme: dark) {
.ag-banner {
--surface: #1c1a0f;
--surface-text: #fef3c7;
--surface-text-muted: #d97706;
--accent: #fbbf24;
--btn-fill: #b45309;
--btn-text: #ffffff;
--link: #fcd34d;
--border: #44381a;
}
}

Near-black OLED (max contrast):

@media (prefers-color-scheme: dark) {
.ag-banner {
--surface: #000000;
--surface-text: #ffffff;
--surface-text-muted: #a1a1aa;
--accent: #60a5fa;
--btn-fill: #2563eb;
--btn-text: #ffffff;
--link: #93c5fd;
--border: #27272a;
}
}

Combined light + dark in one block:

/* Light theme */
.ag-banner {
--accent: #0f766e;
--surface: #f0fdfa;
--surface-text: #134e4a;
}
/* Dark theme overrides */
@media (prefers-color-scheme: dark) {
.ag-banner {
--accent: #2dd4bf;
--surface: #0d1a18;
--surface-text: #ccfbf1;
}
}

Dark mode applies equally to all buttons — no button becomes less visible in the dark palette. Ensure you verify contrast ratios in dark mode independently of light mode:

  • --surface-text on --surface: ≥ 4.5:1
  • --btn-text on --btn-fill: ≥ 4.5:1
  • --link on --surface: ≥ 4.5:1

No branding or required GDPR elements are modified in this recipe.