Q39: How does the light-dark() CSS color function simplify dark mode theming?

The light-dark(LIGHT_COLOR, DARK_COLOR) CSS function sets two color choices in a single declaration. The browser automatically selects the appropriate color based on the current active color-scheme rule.

Declarative Theme Colors with light-dark()
:root {
  color-scheme: light dark;
}

.card {
  background-color: light-dark(#ffffff, #1e1e1e);
  color: light-dark(#111111, #f5f5f5);
}

light-dark() switches background and text colors automatically based on the active color-scheme.

Key Takeaways
  • Supplies light and dark color options inside a single function declaration.

  • Requires active color-scheme configuration to switch mode colors dynamically.

Knowledge Check

What property must be declared on an element or root scope for light-dark() to function?