Web · Components
Switch
On/off switch.
2 exports
Live example
Preview
Code
Events
- Events appear here when you interact with the preview.
Import
On/off switch. Used for settings that take effect immediately (e.g. turn on notifications). For choices that need a save button Checkbox fits better.
Built on a real <input type="checkbox" role="switch">; works with forms and even before JavaScript loads. Usable in server components. On touch screens the touch area is enlarged to 44 px height.
Examples
SwitchProps
interfaceProps of the Switch component.
Extends: Omit<ComponentProps<"input">, "type" | "size">
| Name | Type | Default | Description |
|---|---|---|---|
size? | "sm" | "md" | "md" | |
onCheckedChange? | (checked: boolean) => void | Called with the new value when the state changes. A shortcut for onChange. | |
label? | ReactNode | Label next to the switch; fully clickable. If given, className is applied to the label itself. | |
description? | ReactNode | Description below the label; screen readers read it with the switch. | |
tooltip? | TooltipProp | Tooltip shown on hover, keyboard focus or long press on touch screens. Opens from the whole label and screen readers read it with the switch. See TooltipProp. | |
effect? | EffectProp | Effect or effects of the switch (e.g. "pulse", "glow"). If omitted, UIProvider appearance.defaults.switch.effect. See BuiltinEffect. |