Theme Toggle Effect Circle Blur Top Left
A view-transition style for theme toggles that reveals the new color scheme from the top-left corner with a soft, blurred circular mask that expands across the viewport. It applies globally through CSS and is activated when a theme switch runs inside document.startViewTransition.
Installation
Usage
import { useTheme } from 'next-themes'export function ModeToggle() { const { resolvedTheme, setTheme } = useTheme() const toggle = () => { const next = resolvedTheme === 'dark' ? 'light' : 'dark' if (!document.startViewTransition) return setTheme(next) document.startViewTransition(() => setTheme(next)) } return <button onClick={toggle}>Toggle theme</button>}- Adding a playful, glowing theme-switch animation to a light/dark mode toggle in a marketing site or app header
- Giving a theme toggle a directional origin at the top-left corner of the viewport, e.g. a button in the left navigation
- Replacing a plain instant theme swap with a smooth, branded transition that still stays lightweight (CSS only)
Examples
Toggle button with next-themes
Wraps the theme change in document.startViewTransition so the installed top-left blur mask animates the switch. Falls back to an instant change where the View Transitions API is unavailable.
import { useTheme } from 'next-themes'export function ModeToggle() { const { resolvedTheme, setTheme } = useTheme() const toggle = () => { const next = resolvedTheme === 'dark' ? 'light' : 'dark' if (!document.startViewTransition) return setTheme(next) document.startViewTransition(() => setTheme(next)) } return ( <button type='button' onClick={toggle} aria-label='Toggle theme'> Toggle theme </button> )}Toggle using a class on the html element
Works without a theme library by toggling the dark class on document.documentElement inside the view transition. The .dark selectors in the style rely on that class.
import { useState } from 'react'export function ThemeSwitch() { const [dark, setDark] = useState(false) const toggle = () => { const update = () => { document.documentElement.classList.toggle('dark') setDark((value) => !value) } if (!document.startViewTransition) return update() document.startViewTransition(update) } return ( <button type='button' onClick={toggle} aria-pressed={dark}> {dark ? 'Light mode' : 'Dark mode'} </button> )}Accessibility
- The style itself is purely visual and adds no focusable elements, roles, or ARIA attributes; the accessible name and state must come from the toggle control.
- Respect prefers-reduced-motion by skipping startViewTransition or disabling the animation for users who request reduced motion, since the mask scales across the full viewport over one second.
- Ensure the toggle button has a clear accessible name such as 'Toggle theme' and, when it is a stateful switch, exposes its state with aria-pressed or an equivalent label.
- Keep the toggle's color contrast sufficient in both light and dark themes, because the transition only changes the page colors between states and does not alter the control's contrast.
Docs written by anthropic:claude-haiku-5-5 from the registry source.
Use with Coding Agent
Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.
Use the "Theme Toggle Effect Circle Blur Top Left" component (ncdai/theme-toggle-effect-circle-blur-top-left) from its shadcn registry.1. Install it with: npx shadcn@latest add https://chanhdai.com/r/theme-toggle-effect-circle-blur-top-left.json2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { useTheme } from 'next-themes'export function ModeToggle() { const { resolvedTheme, setTheme } = useTheme() const toggle = () => { const next = resolvedTheme === 'dark' ? 'light' : 'dark' if (!document.startViewTransition) return setTheme(next) document.startViewTransition(() => setTheme(next)) } return <button onClick={toggle}>Toggle theme</button>}```Files & dependencies
Looks similar, elsewhere
There is no screenshot of this item to compare yet.