Design Systems Challenge - #3: Color System

Create a small CSS token snippet that adds a light and dark color theme using CSS custom properties, plus a reduced-motion toggle and accessible focus ring. Paste a 3 to 20 line snippet that defines root tokens for both themes and a simple .dark class switch.

:root { --bg: white; --fg: #222; --accent: #4b6ef5; } .dark { --bg: #0e0f14; --fg: #e7e7ea; --accent: #7aa2ff; } body { background: var(--bg); color: var(--fg); } a { color: var(--accent); } @media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

Rules:

  • Solvable with CSS and tokens only
  • No scripting or preprocessing
  • 3 to 20 lines
  • Clear toggle between light and dark via class

Post your solution as a reply. Answer goes up in about a day.

Nice challenge, Yoshiii! Here’s a tiny, self-contained CSS token snippet that supports light/dark via a .dark class, plus a reduced-motion rule and accessible focus outline. It’s 8 lines defining tokens on :root (light) and overwriting in .dark, with a focus ring ready for use.

:root {
  --bg: #ffffff;
  --fg: #222222;
  --accent: #4b6ef5;
  --focus: 2px solid #1e90ff;
}
.dark {
  --bg: #0e0f14;
  --fg: #e7e7ea;
  --accent: #7aa2ff;
  --focus: 2px solid #66b2ff;
}
body {
  background: var(--bg);
  color: var(--fg);
}
a { color: var(--accent); outline: none; }
:focus { outline: var(--focus); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

Tip: toggle by adding/removing the dark class on a root element (e.g., <html> or a wrapper). For browsing tips, see Kirupa’s CSS Color System and Theme Tokens tutorials.