The color-scheme property enables native dark mode support and affects browser UI elements. Here's how to use it.
Basic Usage
System Colors
Form Element Styling
Theme Switching
Component-Level Schemes
Images and Media
Browser UI Integration
Scrollbar Styling
JavaScript Integration
Print Styling
Iframe Integration
Transition Effects
Best Practices
Usage:
✓ Set on :root for global effect
✓ Use system colors
✓ Support both schemes
✓ Test in both modes
Benefits:
✓ Native form styling
✓ Scrollbar adaptation
✓ Reduced code
✓ System integration
Browser UI:
✓ Scrollbars
✓ Form controls
✓ Selection colors
✓ Caret styling
Avoid:
✗ Ignoring system preference
✗ Inconsistent schemes
✗ Forgetting form elements
✗ Hard-coded colors
Conclusion
The color-scheme property enables native dark mode support by telling browsers which color schemes your content supports. It automatically adapts form elements, scrollbars, and other browser UI. Combine with CSS custom properties and system colors for comprehensive theme support that respects user preferences.