Skip to content

Frontend

Add dark mode to a Vite app

A short Build-mode task with clear acceptance criteria, then a hand-made tweak and a deployment.

Codexa Team1 min readBeginner20 min

On this page

A small feature with acceptance criteria shows how to get predictable results from Build mode.

Step 1: The prompt

Text
Add dark mode:
- a toggle button in the header with an accessible label
- Tailwind "class" strategy; add the `dark` class on <html>
- respect prefers-color-scheme on first load, then remember the choice
  in localStorage
- no new dependencies
Done when `npm run build` passes and both themes render without unstyled flashes.

Step 2: What to expect

The plan should mention tailwind.config (or the Tailwind v4 CSS variant the template uses), the header component and a tiny script that applies the stored theme before React renders. The validating stage runs the build.

Step 3: Check it in the preview

Run the preview, toggle, reload. If the page flashes light before going dark, the theme script runs too late; ask in Fix mode with that sentence as the error description.

Step 4: Adjust by hand

Open the component and change the icon or colours. Save; the preview updates.

Step 5: Deploy

Deploy to Codexa hosting and test the live URL on a phone. Rollback is available if a later change regresses it.