Skip to content
VenusUI
Get started

Toggle Switch

An on/off switch whose thumb slides with a little overshoot.

Preview

Installation

npx shadcn@latest add @venusui/toggle-switch

Run this in a project set up with shadcn. If you haven’t set it up yet, run npx shadcn@latest init first.

Files added to your project

Paths use the default shadcn aliases. The CLI follows the aliases in your components.json.

  • @/components/ui/toggle-switch.tsx

Usage

The code behind the preview above.

toggle-switch-demo.tsx

import { ToggleSwitch } from "@/components/ui/toggle-switch"

export default function ToggleSwitchDemo() {
  return (
    <div className="space-y-3">
      <ToggleSwitch label="Email notifications" defaultChecked />
      <ToggleSwitch label="Weekly summary" size="sm" />
    </div>
  )
}

API reference

PropTypeDefaultDescription
checkedboolean—Controlled state.
defaultCheckedbooleanfalseInitial state.
onCheckedChange(checked: boolean) => void—Called on toggle.
labelReactNode—Visible label. Without it, pass aria-label.
size"sm" | "md""md"Switch size.

All <button> props except onChange and value.

Requirements

  • React 19 and Tailwind CSS v4.

Customization

  • The on state uses your theme’s primary color; edit bg-primary in the file to change it.

Accessibility

  • role="switch" with aria-checked; Space and Enter toggle it; clicking the label toggles it too.
  • No overshoot animation with reduced motion.

Troubleshooting

It submits a form.
It is type="button". Store its value in a hidden input if a form needs it.
Unknown registry "@venusui"
Your shadcn CLI couldn’t find the namespace in the shadcn registry index. Use the latest CLI (npx shadcn@latest), install by URL, or register it with its address: npx shadcn@latest registry add @venusui=https://venusui.com/r/{name}.json.
No components.json found
Run npx shadcn@latest init in your project first.
Loading preview

A text field whose label sits inside and floats above on focus or when filled.

Loading preview

A number field with minus and plus buttons, clamped to a range.

Loading preview

OTP Input

Inputs

One-time code entry in separate boxes with paste, autofill and keyboard navigation.