Public
Like
meow
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data β all from the browser, and deployed in milliseconds.
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.
- 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
- CSS Variables: Uses CSS custom properties that change based on
@media (prefers-color-scheme: dark) - JavaScript Detection: Uses
matchMediaAPI 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
- Pure HTML, CSS, and JavaScript (no external dependencies)
- Uses CSS custom properties for theme variables
- Implements
prefers-color-schememedia queries for automatic theme switching - JavaScript
matchMediaAPI for programmatic detection - Event listeners for real-time theme change detection
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!
- Windows: Settings β Personalization β Colors
- macOS: System Preferences β General β Appearance
- iOS/Android: Settings β Display β Dark mode
βββ index.ts # Main HTTP handler serving the website
βββ README.md # This documentation