Add a dark mode toggle that remembers itself
By VibeCoderHQ|Published on 4/26/2026
PromptingNext.jsCursor
Adds a proper dark mode instead of a toggle that flickers or forgets your choice. Works in Cursor, Claude Code, and v0. The two details that matter most are killing the flash of unstyled theme on load and centralizing colors as tokens, so define the palette once and every component follows.
Prompt Text
Add light and dark mode to my [FRAMEWORK] app using [Tailwind if present / CSS variables].
Requirements:
1. A toggle in the header with three options or a simple switch: light, dark, and system (follow the device setting).
2. Remember the user's choice across page loads and reloads using localStorage.
3. No flash of the wrong theme on first paint. Set the theme before the page renders.
4. Use CSS variables (or Tailwind's dark class) for colors so I define each color once and both themes read from it. Do not hardcode hex values all over the components.
5. Make sure text stays readable in both themes and check contrast on buttons, borders, muted text, and any cards.
Approach:
- First, set up the color tokens (background, foreground, card, border, muted, primary) for both themes in one place.
- Then wire up the toggle and the no-flash script.
- Then sweep the existing components and replace hardcoded colors with the tokens.
Show me the token setup first so I can approve the palette, then do the rest. If I am using [shadcn/ui], follow its theming convention.Join the vibe coder community
Weekly prompts, tools, and success stories to help you build and monetize with AI.
Unsubscribe any time.
Reviews
No reviews yet. Be the first to review!