role="switch" to a checkbox input for toggle switch styling. This provides accessible switch components using native HTML.
Basic Switch
A simple toggle switch using a checkbox with the switch role.Unchecked
Default unchecked state.Checked
Add thechecked attribute for the checked state.
Disabled State
Switches can be disabled using thedisabled attribute.
Accessibility
The switch component uses semantic HTML with proper ARIA roles:- Uses native
<input type="checkbox">for keyboard and screen reader support role="switch"provides the correct semantic meaning- Wrapping in
<label>ensures the text is associated with the control - Supports standard keyboard interaction (Space to toggle)
Usage Notes
No JavaScript is required. The switch is a pure CSS implementation using the checkbox’s native checked state.
Styling
Switches use CSS custom properties for theming:--primary- Switch background when checked--background- Switch thumb color--input- Switch background when unchecked--radius-full- Border radius for switch track and thumb--shadow-small- Thumb shadow--transition- Animation duration for thumb movement