Controls

Switch

A toggle component that allows users to enable or disable a setting with a smooth transition effect. It provides clear visual feedback for on/off states.

Loading...

Installation

Install the component via the CLI in one command.

npx shadcn@latest add @intentui/switch

Composed components

When you install this component via the CLI, it automatically loads all composed components, so you don’t need to add them individually.

Manual installation

Use this approach if you prefer to install and wire up the component yourself instead of using the CLI.

npm install react-aria-components tailwind-merge

Anatomy

import { Description } from "@/components/ui/field"
import { Switch, SwitchLabel } from "@/components/ui/switch"
<>
  <Switch value="profileVisible">
    <SwitchLabel>Public profile</SwitchLabel>
    <Description>Allow others to see your profile.</Description>
  </Switch>
  <Switch value="searchEngineIndexing">
    <SwitchLabel>Search engine indexing</SwitchLabel>
    <Description>
      Allow search engines to index your profile.
    </Description>
  </Switch>
  <Switch defaultSelected value="twoFactor">
    <SwitchLabel>Two-factor authentication</SwitchLabel>
    <Description>
      Add an extra layer of security to your account.
    </Description>
  </Switch>
  <Switch value="activityStatus">
    <SwitchLabel>Show activity status</SwitchLabel>
    <Description>Let others see when you're online.</Description>
  </Switch>
</>

Examples

Description

You can add a description to the switch by passing the description prop or using the Description component.

Loading...

Controlled

You can manage the switch's state by setting the isSelected prop.

Loading...

Uncontrolled

You can also use the uncontrolled version of the switch.

Loading...

Disabled

A disabled switch cannot be toggled and is non-interactive.

Loading...

Component API

Switch

The Switch component toggles a setting on or off.

PropTypeDefault
classNamestring-

SwitchLabel

The SwitchLabel component renders the switch label.

PropTypeDefault
classNamestring-

See the React Aria for the full API reference.

Unlock the full power of
Intent UI Design

Build modern web apps faster with 1000+ resources across components, blocks, patterns, templates, and starter kits.

Learn more