Skip to main content

Switch

A switch component for toggling between two states. Built on Radix UI primitives with smooth animations. Perfect for settings, preferences, and feature toggles.

Installation
Loading...
Import
Loading...

Usage

Use Switch for binary toggles in settings, preferences, and feature flags. Prefer Switch over Checkbox when the action is immediate and doesn't require form submission. Always pair with descriptive labels. Use controlled state for form integration.

Design Guidelines

Maintain consistent switch styling throughout your application. Use switches for immediate actions and toggles. Group related switches visually. Provide clear labels and optional descriptions. Use appropriate spacing in settings panels.

Basic Usage

Simple switch with label

Loading...

States

Different switch states

Loading...

Controlled Switch

Switch with controlled state

Loading...

Notification Settings

Comprehensive notification preferences

Loading...

Privacy Settings

Privacy and security preferences

Loading...

Form Integration - Settings Form

Settings form with controlled switches for form submission

Loading...

packages.sections.api

Component props and API reference This component supports common style props for spacing, layout, flexbox, grid, and more. Style props export common Tailwind classes as props to help in building consistent UI. For detailed documentation and examples, see the Style Props documentation.

packages.propsTable.headers.namepackages.propsTable.headers.typepackages.propsTable.headers.defaultpackages.propsTable.headers.description
checked
boolean

Controlled checked state

defaultChecked
boolean

Uncontrolled default checked state

onCheckedChange
(checked: boolean) => void

Callback fired when checked state changes

disabled
booleanfalse

Whether the switch is disabled

className
string

packages.commonProps.className.description

asChild
booleanfalse

packages.commonProps.asChild.description.part1 packages.commonProps.asChild.description.linkText packages.commonProps.asChild.description.part2

Accessibility

Accessibility features and considerations

Switch includes proper ARIA attributes. Always associate with labels using htmlFor/id. Screen readers announce checked state. Keyboard accessible with Space to toggle. Provide clear labels that describe what the switch controls.