UI & Design SystemsBy PaletteKey Team 8 min read

How to Build Light and Dark Theme Color Systems

Architecting dark mode with semantic remapping, surface elevation, and contrast preservation.

Key Technical Takeaway

Building a light and dark theme system requires semantic token remapping rather than simple color inversion. Learn how to handle surface elevation, reduce eye strain, and preserve brand contrast.

Why Dark Mode is Not Simple Color Inversion

Inverting light mode colors directly (e.g. converting white to pure #000000 and black text to pure #FFFFFF) results in harsh visual vibration, lost depth, and severe haloing effects for users with astigmatism. Dark mode requires purposeful semantic remapping and desaturated accents.

Surface Elevation Hierarchy in Dark Themes

In light mode, shadows create depth and indicate Z-index elevation. In dark mode, shadows are less visible against dark backgrounds. Depth is communicated by making higher elevation surfaces progressively lighter:

Elevation TierUI ComponentLight Mode SurfaceDark Mode Surface
Base Canvas (0dp)Page background#F8FAFC (slate-50)#090D16 (slate-950)
Card / Panel (1dp)Containers, cards, sidebar#FFFFFF (white)#1E293B (slate-800)
Dropdown / Menu (2dp)Popovers, context menus#FFFFFF + shadow-md#334155 (slate-700)
Modal Overlay (3dp)Dialog boxes, drawers#FFFFFF + shadow-xl#475569 (slate-600)

Implementing Theme Switching in CSS

Using CSS custom properties and `[data-theme="dark"]` attribute selectors to switch semantic token values seamlessly:

/* Light Theme (Default) */
:root {
  --bg-canvas: #F8FAFC;
  --bg-surface: #FFFFFF;
  --text-primary: #0F172A;
  --text-secondary: #475569;
  --border-subtle: #E2E8F0;
  --action-primary: #2563EB;
}

/* Dark Theme Remapping */
[data-theme="dark"] {
  --bg-canvas: #090D16;
  --bg-surface: #1E293B;
  --text-primary: #F8FAFC;
  --text-secondary: #94A3B8;
  --border-subtle: #334155;
  --action-primary: #3B82F6; /* Slightly lighter/desaturated for dark contrast */
}

/* Usage in UI Components */
body {
  background-color: var(--bg-canvas);
  color: var(--text-primary);
}
.card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
}

Key Principles for Dark Mode Usability

Maintain readability and reduce eye fatigue across themes:

  • Avoid pure #000000 backgrounds; use dark slate (#090D16 or #0F172A) to reduce harsh contrast.
  • Avoid pure #FFFFFF text on dark backgrounds; use #F8FAFC or #F1F5F9 to eliminate halation.
  • Desaturate primary brand accents in dark mode to prevent visual vibration against dark surfaces.
  • Verify that status alerts (error red, success green) pass WCAG 4.5:1 on dark surfaces.

Put Theory into Practice with Free Color Tools

Apply the concepts from this guide directly in your web workflow with our interactive tools.