Join our Discord Community
Interactive

Theme Switcher

Interactive theme toggle component for React and Next.js applications. Built with TypeScript support, Tailwind CSS styling, and shadcn/ui design featuring system preference detection, smooth transitions, and accessibility features.

Powered by

Loading component...

Installation

npx shadcn@latest add https://www.shadcn.io/registry/theme-switcher.json
npx shadcn@latest add https://www.shadcn.io/registry/theme-switcher.json
pnpm dlx shadcn@latest add https://www.shadcn.io/registry/theme-switcher.json
bunx shadcn@latest add https://www.shadcn.io/registry/theme-switcher.json

Features

  • Triple theme modes - Light, dark, and system preference detection using JavaScript media queries
  • Controlled/uncontrolled - Both controlled and uncontrolled state management for React applications
  • Smooth transitions - Animated theme switching with Motion library integration for Next.js projects
  • System detection - Automatic dark mode following OS preferences using TypeScript event handling
  • Icon animations - Sun/moon icon transitions with Lucide icons using Tailwind CSS transforms
  • Accessibility features - Keyboard navigation and proper ARIA labels using shadcn/ui patterns
  • Persistent storage - Theme preference saved to localStorage using JavaScript storage APIs
  • Open source - Free theme switcher component with Radix UI primitives

Examples

Uncontrolled mode

Check the console for the onChange event.

Loading component...

Use Cases

  • Application headers - Global theme control in navigation bars and toolbars
  • Settings panels - User preference configuration in app settings pages
  • Dashboard controls - Quick theme switching in admin and data interfaces
  • Content platforms - Reader-friendly dark mode toggles for articles and documentation

Implementation

Built with next-themes for system detection and persistence. Uses Motion for icon animations. Supports controlled mode with onChange callbacks. Automatically syncs with system preferences.