Switch

A control that allows the user to toggle between checked and not checked.

inputs
toggle
selection
control

Preview

Variants

Basic switch control.

Code

TSX
1
2
3
4
5
6
7
8
9
10
11
import { Switch } from "@/components/ui/switch"
import { Label } from "@/components/ui/label"

export function SwitchDemo() {
  return (
    <div className="flex items-center space-x-2">
      <Switch id="airplane-mode" />
      <Label htmlFor="airplane-mode">Airplane Mode</Label>
    </div>
  )
}

API Reference

PropTypeDefaultDescription
checkedboolean-Whether the switch is checked.
defaultCheckedboolean-Whether the switch is checked by default.
onCheckedChangefunction-Event handler called when the checked state changes.
disabledbooleanfalseWhether the switch is disabled.