Theme Toggle Effect Circle Blur
A CSS-only theme-switch effect that reveals the new light or dark theme through a blurred circle expanding from the viewport center via the View Transitions API. It installs no components; it adds base-layer CSS and a theme easing variable.
Installation
Usage
export function ThemeToggle() { const toggle = () => { const apply = () => document.documentElement.classList.toggle('dark'); if (!document.startViewTransition) { apply(); return; } document.startViewTransition(apply); }; return ( <button type="button" onClick={toggle}> Toggle theme </button> );}- Adding a polished, circular reveal animation to a light/dark theme toggle in a web app or landing page
- Giving a theme switch a noticeable but smooth transition without writing custom animation code
- Enhancing a site that already uses the browser View Transitions API (document.startViewTransition) for theme changes
- Applying a consistent blurred-circle motion language to other full-page state changes that use view transitions
Examples
Basic dark-mode toggle button
A button that toggles the dark class on the html element inside document.startViewTransition, which triggers the blurred circle reveal.
export function ThemeToggle() { const toggle = () => { const apply = () => document.documentElement.classList.toggle('dark'); if (!document.startViewTransition) { apply(); return; } document.startViewTransition(apply); }; return ( <button type="button" onClick={toggle} aria-label="Toggle dark mode"> Theme </button> );}Toggle with persisted preference
Stores the chosen theme in localStorage and applies it through the same view-transition-wrapped update, so the effect plays on user-initiated changes.
export function PersistentThemeToggle() { const toggle = () => { const apply = () => { const isDark = document.documentElement.classList.toggle('dark'); localStorage.setItem('theme', isDark ? 'dark' : 'light'); }; if (!document.startViewTransition) { apply(); return; } document.startViewTransition(apply); }; return ( <button type="button" onClick={toggle}> Switch theme </button> );}Respecting reduced motion
Skips the view transition when the user prefers reduced motion, so the theme still changes without the animated circle.
export function AccessibleThemeToggle() { const toggle = () => { const apply = () => document.documentElement.classList.toggle('dark'); const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches; if (!document.startViewTransition || reduceMotion) { apply(); return; } document.startViewTransition(apply); }; return ( <button type="button" onClick={toggle}> Toggle theme </button> );}Accessibility
- The item exposes no props or components; accessibility depends on the button or control that calls document.startViewTransition.
- Give the toggle control an accessible name (visible text or aria-label) and expose its state if it is a switch, for example with aria-pressed.
- Respect prefers-reduced-motion by skipping the view transition, as shown in the third example, since the effect is a large full-screen animation.
- The theme change itself is not delayed; the animation is visual only, so the new theme is still applied for assistive technologies and keyboard users.
- Browsers without View Transitions support will change the theme instantly, so always guard the call with a feature check.
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" component (ncdai/theme-toggle-effect-circle-blur) from its shadcn registry.1. Install it with: npx shadcn@latest add https://chanhdai.com/r/theme-toggle-effect-circle-blur.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):```tsxexport function ThemeToggle() { const toggle = () => { const apply = () => document.documentElement.classList.toggle('dark'); if (!document.startViewTransition) { apply(); return; } document.startViewTransition(apply); }; return ( <button type="button" onClick={toggle}> Toggle theme </button> );}```Files & dependencies
Looks similar, elsewhere
There is no screenshot of this item to compare yet.