Premium

Vue Theme Toggle with Persisted Light/Dark Mode

By FrontendAtlas Team · Updated Jan 30, 2026

Add a global light/dark theme toggle in the top-right of the page using Vue 3. The selected theme should be stored in localStorage and restored when the page reloads. Vue focus: use a global ref/composable to persist theme in localStorage and apply a root attribute.…

  • Render a main page layout with a simple content card and a…
  • Support two themes: "light" and "dark".

What you’ll build / What this tests

This premium vue coding focuses on Vue Theme Toggle with Persisted Light/Dark Mode. You’ll apply vue and composition-api thinking with intermediate level constraints. The prompt emphasizes Add a global light/dark theme toggle in the top-right of the page using Vue 3. The….

Learning goals

  • Translate the prompt into a clear vue API signature and return shape.
  • Apply vue, composition-api, state-management techniques to implement vue theme toggle with persisted light/dark mode.
  • Handle intermediate edge cases without sacrificing readability.
  • Reason about time/space complexity and trade-offs in vue.

Key decisions to discuss

  • Define the exact input/output contract before coding.
  • Prioritize predictable edge-case handling over micro-optimizations.

Evaluation rubric

  • Correctness: covers required behaviors and edge cases.
  • Clarity: readable structure and predictable control flow.
  • Complexity: avoids unnecessary work for large inputs.
  • API discipline: no mutation of inputs; returns expected shape.
  • Testability: solution is easy to unit test.

Constraints / Requirements

  • Render a main page layout with a simple content card and a theme toggle control in the top-right…
  • Support two themes: "light" and "dark".
  • Store the current theme in a single source of truth (e.g. a module-level ref / small theme composable).
  • Persist the selected theme in localStorage under a stable key.
  • On initial load, read the theme from localStorage and apply it before the user interacts.
  • Apply the theme at the document level by setting data-theme on , so that the existing CSS can…
  • You only need to edit /src/App.vue (the template and ). The CSS files are already wired to respond…
  • By default, the app starts in light mode if there is no previous theme stored.
  • If the user toggles to dark mode, the page background, text, and card colors change.
  • Reloading the page keeps the user’s last theme selection (light or dark).

Mini snippet (usage only)

// Example usage
const input = /* vue theme toggle with persisted light/dark mode input */;
const result = solve(input);
console.log(result);

// Edge case check
const empty = input ?? null;
const fallback = solve(input);
console.log(fallback);

// Expected: describe output shape, not the implementation
// (no solution code in preview)

Common pitfalls

  • Mutating inputs instead of returning a new value.
  • Skipping edge cases like empty input, duplicates, or nulls.
  • Overlooking time complexity for large inputs.

Related questions

Upgrade to FrontendAtlas Premium to unlock this challenge. Already upgraded? Sign in to continue.