Skip to main content

Installation

Usage

Component API

Switch

Toggle switch component built on Radix UI Switch.
Props:
  • size - Switch size ("sm" | "default")
  • checked - Controlled checked state
  • defaultChecked - Default checked state
  • onCheckedChange - Callback when checked state changes
  • disabled - Disables the switch
  • aria-invalid - Shows error state styling

Implementation

The switch includes a thumb that animates:

Examples

Basic Switch

With Label

Switch with associated label:

Controlled Switch

With Description

Switch with label and description:

Disabled State

Invalid State

Show validation error:

Different Sizes

Settings Panel

Practical example:

Form Integration

With React Hook Form:

Choice Card

Clickable card-style switch:

Accessibility

  • Uses role="switch" semantics
  • Keyboard accessible (Space to toggle)
  • Proper ARIA attributes
  • Focus visible states
  • Associated labels via htmlFor
  • Screen reader announcements

API Reference

See the Radix UI Switch documentation for complete API reference.