• Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
jeffreyyoung

jeffreyyoung

meow

Public
Like
meow
Home
Code
2
README.md
H
index.ts
Branches
1
Pull requests
Remixes
History
Environment variables
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.
Sign up now
Code
/
Code
/
Search
README.md

Color Scheme Detector

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

  1. CSS Variables: Uses CSS custom properties that change based on @media (prefers-color-scheme: dark)
  2. JavaScript Detection: Uses matchMedia API to detect the current color scheme
  3. Event Listeners: Listens for changes in color scheme preference to update in real-time
  4. 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
Code
README.md
H
index.ts
FeaturesVersion controlCode intelligenceCLIMCP
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Open Source Pledge
Terms of usePrivacy policyAbuse contact
Β© 2025 Val Town, Inc.