Switch

A toggle switch for binary on/off states.

Import

Usage

Colors

Sizes

Disabled

Default Checked

Controlled

Form Usage

Enable notifications

Custom Styling

Data Attributes

  • -
    data-slot="switch"Main switch element identifier
  • -
    data-slot="switch-thumb"Switch thumb/circle element identifier
  • -
    data-state="checked"Present when the switch is on
  • -
    data-state="unchecked"Present when the switch is off

Accessibility

Keyboard Support

  • -
    SpaceToggles the switch on/off
  • -
    EnterToggles the switch on/off
  • -
    TabMoves focus to the next focusable element

ARIA Attributes

  • -
    role="switch"Identifies the element as a switch
  • -
    aria-checkedIndicates the current state (true/false)
  • -
    aria-disabledSet when the switch is disabled
  • -
    aria-labelRequired to provide context for screen readers

Switch Props

AttributeTypeDefaultDescription
color'default' | 'primary' | 'secondary' | 'success' | 'warning' | 'danger''primary'The color scheme of the switch.
size'sm' | 'md' | 'lg''md'The size of the switch.
checkedboolean-The controlled checked state of the switch.
defaultCheckedboolean-The default checked state (uncontrolled).
onCheckedChange(checked: boolean) => void-Callback when the checked state changes.
disabledbooleanfalseWhether the switch is disabled.
requiredbooleanfalseWhether the switch is required in a form.
namestring-The name of the switch for form submission.
valuestring'on'The value of the switch for form submission.
classNamestring-Additional CSS classes for the switch container.
thumbClassNamestring-Additional CSS classes for the switch thumb.