Dark mode
Introduction
The Dark mode component provides a toggle for switching between light and dark color schemes. It uses system preferences, persists user choices, and follows accessibility best practices.
When to use
- Website theming
- User interface customization
- Reducing eye strain in low-light conditions
- Respecting user system preferences
- Battery saving on OLED displays
Usage
Props
Prop | Type | Default | Description |
---|---|---|---|
initialMode | 'light' | 'dark' | 'auto' | 'auto' | Sets the initial color scheme mode |
Accessibility features
- Uses semantic button element
- Proper ARIA attributes (
aria-pressed
,aria-label
) - Keyboard navigation support
- Respects user’s motion preferences
- High contrast icons
- Maintains focus states
- Persists across page loads using
localStorage