HelpTribe.

Switch

Toggle switch for binary settings. Use for on/off states, feature flags, and preference toggles.

Installation

$ npx shadcn@latest add switch

Preview

Usage (React/TSX)

"use client"
import { useState } from "react"
import { Switch } from "@/components/ui/switch"

export default function Settings() {
  const [enabled, setEnabled] = useState(false);
  return (
    <div className="flex items-center gap-3">
      <Switch checked={enabled} onCheckedChange={setEnabled} />
      <span>Enable notifications</span>
    </div>
  )
}

Props

PropTypeDefaultDescription
checkedbooleanfalseWhether the switch is on.
onCheckedChange(checked: boolean) => voidβ€”Callback when the switch is toggled.
disabledbooleanfalseDisables the switch.
classNamestringβ€”Additional CSS classes to apply.