CSS3 & Modern Layouts (50 Qs)•Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)
Implementing Dark Mode with `color-scheme` and `light-dark()`.
senior LevelCode ExampleSystem Design
In Simple Words: Modern CSS provides first-class color scheme switching:
css
:root {
color-scheme: light dark;
--bg: light-dark(#ffffff, #0f172a);
--text: light-dark(#0f172a, #f8fafc);
}
body {
background-color: var(--bg);
color: var(--text);
}
Automatically switches between light and dark palettes based on OS preferences (prefers-color-scheme) with zero custom JavaScript!