Skip to main content

Switch

Toggle control for binary states. Perfect for settings, preferences, and feature toggles with full keyboard navigation and RTL support.

Preview

Installation

Terminalbash

Usage

Reacttsx

Examples

With Label

tsx

Settings Panel

Receive emails about new products and features

Receive emails about your account security

Receive emails about product updates and announcements

tsx

Disabled State

tsx

Controlled Component

Status: Off

tsx

In Forms

Privacy Settings

tsx

Props

NameTypeDefaultDescription
checked
booleanfalseThe controlled checked state of the switch
defaultChecked
booleanfalseThe default checked state (uncontrolled)
onCheckedChange
(checked: boolean) => voidundefinedEvent handler called when the checked state changes
disabled
booleanfalseDisables the switch
required
booleanfalseMarks the switch as required
name
stringundefinedThe name of the switch for form submission

Accessibility

Keyboard Navigation

  • Tab: Move focus to/from switch
  • Space: Toggle switch state

Always Use Labels

Always pair switches with labels using the htmlFor and id attributes. This provides clear context about what the switch controls.

Screen Readers

The switch role is automatically announced with its current state (on/off). The label describes what the switch controls.

Visual Feedback

Switches provide clear visual feedback through color, position, and animation to indicate their state.

RTL Considerations

Switches automatically support RTL layout. The switch thumb animates in the correct direction, and labels align properly in both directions.

LTR (English)

RTL (العربية)

Related Components