Build a Light/Dark Mode Toggle Demo Page with Smooth Theme Switching
A single HTML page with a polished light/dark theme switch built on CSS custom properties that defaults to the system theme, honors reduced motion, and uses no storage.
You getone complete HTML file in a single code block, then 3 short ideas to extend it.
The prompt
You are a senior front-end designer who writes clean, accessible HTML, CSS and JavaScript.
Build a demo page called "Fieldnote: Light & Dusk", a landing page for a fictional note-taking app whose main feature is a light/dark theme toggle with smooth switching.
The page has a header with the brand, a sun/moon switch, a short hero, a three-option theme control (System, Light, Dark), a live readout of the current color tokens with swatches, and a sample note card with realistic copy.
Rules:
1. Define every color as a CSS custom property on the root element, with one light set and one dark set selected by a data-theme attribute. Set color-scheme to match.
2. Default to the visitor's prefers-color-scheme, set before first paint so there is no flash, and follow live system changes while System is selected. Do not use localStorage, cookies or any storage.
3. Animate background, text and border colors over about 350ms only during a switch, never on load. Under prefers-reduced-motion, switch instantly and do not slide the thumb.
4. The switch is a real button with role switch and aria-checked; the three options use aria-pressed. Pressing D toggles the theme. Announce the active theme in a polite live region.
5. Use a small palette, a clear type scale with system fonts, generous spacing, visible focus rings and AA contrast in both themes. Layout must work from 360px to 1280px wide.
Output format: one complete HTML file in a single code block, then 3 short ideas to extend it.Example output
Tips and common edits
Why this works
- All colors live in CSS custom properties, so one data-theme attribute swaps the whole page cleanly.
- A tiny head script sets the theme before paint, which prevents a white flash for dark-mode users.
- Transitions are added only during a switch and skipped under reduced motion, so the page never animates on load.
Paste the prompt into ChatGPT, Claude or Gemini. Save the returned code as theme-toggle.html and open it in any browser, or view it in the chat's preview/canvas. Change your OS theme to see it follow along.
Common edits
- Swap the hex values in both token sets to match your brand palette, or add a third high-contrast theme.
- Change the 350ms timing or the D shortcut, or add a circular reveal effect for motion-friendly users.
Prompt details
- By
- Prompts-GPT editors
- Published
Did this prompt work?
Keep exploring
More like this
Build a Playful Animated 404 Error Page with SVG Art and Site Search
A complete single-file 404 page with an original animated hot-air balloon SVG, a live-filtering search box and helpful recovery links that respect reduced motion.
Build a Responsive Navigation Bar With Mega Menu and Mobile Drawer in HTML
A complete single-file site header with a hover, click and arrow-key mega menu on desktop and an animated hamburger drawer with accordions on small screens.
Build a Responsive Three-Tier Pricing Section with Monthly/Yearly Toggle
A single HTML file with three pricing cards, a working billing switch that recalculates prices, a highlighted recommended plan and accessible feature checkmarks.
Build an Accessible Modal, Toast and Tooltip Showcase in One HTML File
You get a single HTML page with a modal dialog, toast notifications and tooltips. All three use focus trapping, Escape handling, correct ARIA roles and live-region announcements.
Design an Accessible Settings Page with Toggles, Segmented Controls and Sliders
A ready-to-paste prompt that builds a polished single-file settings page with custom accessible toggles, segmented controls and sliders that update a live reading preview.
Build a Multi-Step Onboarding Wizard with Stepper and Inline Validation
A four-step onboarding wizard in one HTML file, with a clickable stepper, progress bar, inline validation, a review screen, and keyboard and swipe navigation.
- Build a Button and Form Field States Reference Sheet in a Single HTML File
- Build a Color Blindness Simulator That Previews a Palette on a Dashboard Card
- Build a Drag-to-Arrange Brand Mood Board with Color, Texture and Type Tiles
- Build a Live Accessible Color Palette Builder with a WCAG Contrast Matrix
- Build a Modular Type Scale Specimen with Adjustable Ratio and Base Size
- Build a SaaS Landing Page Hero with a CSS-Drawn Product Mockup