A simple website that automatically detects and displays whether the user's system is set to light mode or dark mode using CSS prefers-color-scheme media queries.
Features
Automatic Detection: Uses window.matchMedia('(prefers-color-scheme: dark)') to detect the user's color scheme preference
Real-time Updates: Listens for changes in color scheme and updates the display immediately
Responsive Design: Adapts colors, icons, and styling based on the detected theme
Visual Feedback: Shows sun (āļø) for light mode and moon (š) for dark mode
Smooth Transitions: CSS transitions provide smooth color changes when switching themes
How It Works
CSS Variables: Uses CSS custom properties that change based on @media (prefers-color-scheme: dark)
JavaScript Detection: Uses matchMedia API to detect the current color scheme
Event Listeners: Listens for changes in color scheme preference to update in real-time
Visual Indicators: Updates text, icons, and styling to reflect the current mode
Technical Implementation
Pure HTML, CSS, and JavaScript (no external dependencies)
Uses CSS custom properties for theme variables
Implements prefers-color-scheme media queries for automatic theme switching
JavaScript matchMedia API for programmatic detection
Event listeners for real-time theme change detection
Usage
Simply visit the website and it will automatically detect your system's color scheme preference. Try changing your system's appearance settings to see the theme switch in real-time!
How to Change Your System Theme:
Windows: Settings ā Personalization ā Colors
macOS: System Preferences ā General ā Appearance
iOS/Android: Settings ā Display ā Dark mode
File Structure
āāā index.ts # Main HTTP handler serving the website
āāā README.md # This documentation