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

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

One HTML file. Save it and open it in any browser.Open full screen

Example: Fieldnote: Light & Dusk, a theme-switching demo page.

The page opens in your system's theme with no flash. Click the sun/moon switch (or press D) to flip themes. Colors fade smoothly unless reduced motion is on. Use System / Light / Dark to choose a mode: in System mode, changing your OS theme updates the page live. The token panel shows each CSS variable's current value, and a live region announces every change.

Written by AI from this prompt. Your results will vary.

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
How prompts are written and checked

Did this prompt work?

Keep exploring

More in Design