Switch

A toggle control for switching between two states, like on and off.

Installation

pnpm dlx stera-ui add switch

Usage

import { Switch } from "@/components/ui/switch"
<Switch />

With Label

Pair with Field and FieldLabel for an accessible labeled switch.

<Field orientation="horizontal">
  <Switch id="airplane-mode" />
  <FieldLabel htmlFor="airplane-mode">Airplane Mode</FieldLabel>
</Field>

With Description

Place FieldContent between the label and switch to add a description.

Receive emails about new products, features, and more.

<Field orientation="horizontal">
  <FieldContent>
    <FieldLabel htmlFor="marketing">Marketing emails</FieldLabel>
    <FieldDescription>
      Receive emails about new products, features, and more.
    </FieldDescription>
  </FieldContent>
  <Switch id="marketing" />
</Field>

Sizes

SizeDescription
defaultStandard size
smCompact size

Disabled

<Field orientation="horizontal" data-disabled="true">
  <Switch id="airplane-mode" disabled />
  <FieldLabel htmlFor="airplane-mode">Airplane Mode</FieldLabel>
</Field>

API Reference

Built on Base UI's Switch primitive.

PropTypeDefault
size"default" | "sm""default"
checkedboolean
defaultCheckedboolean
onCheckedChange(checked: boolean) => void
disabledbooleanfalse
namestring
valuestring