Switch

A toggle switch component for enabling or disabling features and settings.

Default

The default switch sits on a raised control surface. Pass labelClassName="pr-2" to balance the padding around the label.

Slim

slim drops the control surface. Use it inside menus, popovers and settings lists.

Small

size="sm" shrinks the track and thumb for dense toolbars.

Large

size="lg" enlarges the track and thumb for roomier layouts.

Slim and small

Combine slim and size="sm" for compact chart controls.

Green

Set color to green to fill the checked track with green.

Loading

isLoading disables the switch, shows a spinner in the thumb, and sets aria-busy.

Properties

title
string

The label text displayed next to the switch

checked
boolean

The controlled checked state of the switch

defaultChecked
boolean

The default checked state when used as an uncontrolled component

onCheckedChange
(checked: boolean) => void

Event handler called when the checked state changes

disabled
boolean

Whether the switch is disabled

Default: false

required
boolean

When true, indicates that the user must toggle the switch before the owning form can be submitted

name
string

The name of the switch, used when submitting a form

value
string

The value of the switch, used when submitting a form

slim
boolean

Whether to use the slim variant with reduced padding and no shadow

Default: false

size
'default''sm''lg'

The size of the switch

Default: default

color
'default''green'

Fill color of the checked track

Default: default

isLoading
boolean

Disables the switch, shows a spinner in the thumb, and sets aria-busy

Default: false

labelClassName
string

Additional CSS classes to apply to the label

className
string

Additional CSS classes. Applied to both the outer label and the switch track.