The Right Approach

Dark mode is more than inverting colors. It requires thoughtful consideration of contrast ratios, shadow visibility, image handling, and user preference persistence.

CSS Custom Properties

Define your color palette as CSS custom properties at the root level, then override them inside a [data-theme="dark"] selector. This gives you a clean, maintainable system.

Respecting System Preferences

Use the prefers-color-scheme media query as the default, but allow users to override it. Store their preference in localStorage so it persists across sessions.