niceui

Switch

An accessible toggle with a springy thumb. Works controlled or uncontrolled and uses role="switch".

ReactTailwind CSSTypeScriptFormsMIT · Free

Installation

01

Install with the shadcn CLI.

$ npx shadcn@latest add https://niceui.dev/r/switch.json
02

Or copy the source manually into components/ui/switch.tsx. No extra dependencies.

Usage

import { Switch } from "@/components/ui/switch";

export default function Example() {
  return (
    <label className="flex items-center justify-between gap-6 text-sm">
      Notifications
      <Switch defaultChecked label="Notifications" />
    </label>
  );
}

For AI assistants

This page is also available as Markdown and as a shadcn registry item. Use Copy prompt to hand the full source to Claude, Cursor or v0.