Skip to main content

Overview

Off
On
Disabled off
Disabled on
Switch is used for settings that take immediate effect when toggled β€” no form submission needed. Unlike Checkbox, a Switch implies an instant action rather than a selection to be submitted.

Installation


Usage


Variants

Basic

Enable dark mode

On by Default

Email notifications

With Description

Auto-save
Automatically save your work every 5 minutes.

Label on Left

Show sidebar

Disabled

Beta features
Always-on feature

Controlled


API Reference

boolean
Controlled checked state.
boolean
default:"false"
Uncontrolled initial state.
(checked: boolean) => void
Callback fired when the switch state changes.
string
Label text displayed next to the switch.
string
Supporting description shown below the label.
string
default:"right"
Position of the label relative to the switch. Values: left Β· right
boolean
default:"false"
Disables the switch and applies the disabled visual style.
string
Additional Tailwind classes for custom overrides.

Accessibility

  • Switch uses role="switch" with aria-checked for proper screen reader announcement
  • Label is associated via htmlFor / id β€” clicking the label also toggles the switch
  • description is linked via aria-describedby
  • disabled uses the native disabled attribute, removing the element from tab order
  • Space bar toggles the switch when focused β€” follows ARIA switch pattern
  • Focus ring meets WCAG 2.1 AA contrast requirements

Do’s & Don’ts

Do

  • Use Switch for settings that take immediate effect (dark mode, notifications)
  • Always provide a descriptive label β€” never a switch alone
  • Use description to clarify the impact of toggling
  • Place switches in settings panels or preference pages

Don't

  • Don’t use Switch inside a form that requires submission β€” use Checkbox instead
  • Don’t use Switch for multi-select scenarios β€” use Checkbox Group
  • Don’t use ambiguous labels like β€œOn/Off” β€” describe what is being toggled
  • Don’t disable without explaining why in nearby helper text