Switch
Switch is a toggle control for instantly switching settings on and off. Use when changes take immediate effect.
5
Colors
3
Sizes
5
Positions
Radix
Base
Playground
Preview
D32×18pxThumb 16px
Size
Color
Position
Icon
State
Options
<Switch
label="Dark mode"
/>Sizes
smTrack24×14
Thumb12px
Travel10px
Font12px
Gap8px
defaultTrack32×18
Thumb16px
Travel14px
Font14px
Gap10px
lgTrack40×22
Thumb20px
Travel18px
Font16px
Gap12px
| Size | Track | Thumb | Travel | Font | Gap | Preview |
|---|---|---|---|---|---|---|
sm | 24×14px | 12px | 10px | 12px | 8px | |
default | 32×18px | 16px | 14px | 14px | 10px | |
lg | 40×22px | 20px | 18px | 16px | 12px |
Features
With Label
Use the label prop to attach a label to the switch.
<Switch label="Dark mode" />
<Switch label="Email notifications" defaultChecked />Label Position
Change label placement with labelPosition prop. Default is end (right side).
end (default)
start
top
bottom
sides
<Switch label="End" />
<Switch label="Start" labelPosition="start" />
<Switch label="Top" labelPosition="top" />
<Switch label="Bottom" labelPosition="bottom" />
<Switch startLabel="Off" endLabel="On" />With Icon
Display icons inside the thumb with checkedIcon / uncheckedIcon props. Auto-hidden at sm size.
Check / X
Moon / Sun (lg)
<Switch
checkedIcon={<Check />}
uncheckedIcon={<X />}
/>
<Switch
size="lg"
checkedIcon={<Moon />}
uncheckedIcon={<Sun />}
label="Dark mode"
/>States
Off
On
Disabled Off
Disabled On
<Switch />
<Switch defaultChecked />
<Switch disabled />
<Switch disabled defaultChecked />API
Props
checkedundefinedbooleanOn/off state for controlled mode
defaultCheckedundefinedbooleanInitial state for uncontrolled mode
onCheckedChangeundefined(checked: boolean) => voidCallback on state change
size"default""sm" | "default" | "lg"Switch size
labelundefinedstringSwitch label text
labelPosition"end""start" | "end" | "top" | "bottom"Label placement position
startLabelundefinedstringLeft-side label (sides layout)
endLabelundefinedstringRight-side label (sides layout)
color"default""default" | "primary" | "success" | "warning" | "error"Track and icon color when checked
checkedIconundefinedReactNodeIcon displayed in thumb when checked
uncheckedIconundefinedReactNodeIcon displayed in thumb when unchecked
disabledundefinedbooleanDisabled state
requiredundefinedbooleanRequired field
nameundefinedstringForm name attribute
valueundefinedstringForm value attribute. Radix default: "on"
| Name | Type | Default | Description |
|---|---|---|---|
checked | boolean | undefined | On/off state for controlled mode |
defaultChecked | boolean | undefined | Initial state for uncontrolled mode |
onCheckedChange | (checked: boolean) => void | undefined | Callback on state change |
size | "sm" | "default" | "lg" | "default" | Switch size |
label | string | undefined | Switch label text |
labelPosition | "start" | "end" | "top" | "bottom" | "end" | Label placement position |
startLabel | string | undefined | Left-side label (sides layout) |
endLabel | string | undefined | Right-side label (sides layout) |
color | "default" | "primary" | "success" | "warning" | "error" | "default" | Track and icon color when checked |
checkedIcon | ReactNode | undefined | Icon displayed in thumb when checked |
uncheckedIcon | ReactNode | undefined | Icon displayed in thumb when unchecked |
disabled | boolean | undefined | Disabled state |
required | boolean | undefined | Required field |
name | string | undefined | Form name attribute |
value | string | undefined | Form value attribute. Radix default: "on" |
Anatomy
1
2
3
Enable notifications
Track width
32pxTrack height
18pxThumb size
16px1
Track
Switch outer track
2
Thumb
Sliding knob
3
Label
Text label (optional)
Best Practices
✓
Recommended
- ✓Use for settings with immediate effect
- ✓Use with clear labels
- ✓Use for on/off toggles in settings
- ✓Choose default state carefully
✕
Avoid
- ✗Use Checkbox when form submission is needed
- ✗Use Checkbox for multi-select scenarios
- ✗Don't use without a label
- ✗Avoid negative labels (use "Enable" not "Disable")
Accessibility
Keyboard
SpaceToggle on/off
TabMove focus
ARIA Attributes
role="switch"Auto-appliedaria-checkedAuto-managed- Focus indicator
labelexpands click area