
Toggle switch with accessible on/off states.
npx shadcn@latest add https://ui.edbn.me/r/switch.jsonGroups all parts of the switch. Renders a button element.
defaultCheckedbooleanfalseInitial checked state
checkedbooleanControlled checked state
onCheckedChangefunctionCalled when state changes
disabledbooleanfalseDisable switch
readOnlybooleanfalseRead-only state
requiredbooleanfalseRequired field
nativeButtonbooleantrueRender as native button
classNamestring | functionCSS class name
renderReactElement | functionCustom render function
| Attribute | Description |
|---|---|
| data-checked | Present when switch is on |
| data-unchecked | Present when switch is off |
| data-disabled | Present when switch is disabled |
| data-readonly | Present when switch is read-only |
| data-required | Present when switch is required |
| data-valid | Present in valid state |
| data-invalid | Present in invalid state |
| data-dirty | Present when value has changed |
| data-touched | Present when switch has been interacted with |
The thumb that visually toggles. Renders a span element.
classNamestring | functionCSS class name
renderReactElement | functionCustom render function
| Attribute | Description |
|---|---|
| data-checked | Present when switch is on |
| data-unchecked | Present when switch is off |