Skip to content

Components

Switch

An on/off toggle whose knob swells into a clear lens while it crosses the track.

Latest changeImprovedv1.3.8A color prop for the track while on. The examples are now the switch in a few colours, nothing else.
  1. v1.3.8ImprovedA color prop for the track while on. The examples are now the switch in a few colours, nothing else.
  2. v1.3.3ImprovedExamples: a settings list with a disabled switch, the three sizes and the label on either side.
  3. v1.3.0NewThe switch of the first previews: its knob swells into clear glass as it crosses the track.
  4. All changes →
switch.tsx

Use it for

  • A setting that takes effect at once: Wi-Fi, notifications, dark mode.

Not for

  • A choice that is saved later with a form: use Checkbox.
  • More than two states: use Tabs.

Installation

npx shadcn@latest add https://onemorethink.dev/r/switch.json

Usage

app.tsx
import { Switch } from '@/components/liquid-glass/controls/Switch'

const [on, setOn] = useState(false)

<Switch label="Notifications" description="Banners and sounds" checked={on} onChange={setOn} />

Tap to flip, or hold the knob and drag it across. Needs three and UI SDK, like Slider.

API reference

PropTypeDefault
checked

On or off.

booleanfalse
onChange

Called with the new state.

(checked: boolean) => void—
label

Text beside the switch; an empty string leaves the switch alone.

string'Notifications'
description

A second, quieter line under the label.

string—
name

Submits with the form around it under this name.

string—
labelSide

Which side the label sits on.

'left' | 'right''right'
size

Track height 22, 28 or 36 px.

'sm' | 'md' | 'lg''md'
color

The track while on: a hex, rgb() or named colour, not a CSS variable.

string'#3291FF'
theme

Overrides the page theme for this switch.

'light' | 'dark'—
disabled

Dimmed and not interactive.

booleanfalse
lensScale

Size of the travelling lens relative to the resting knob.

number1.55
refraction / knobBounce

How far the lens bends the track; how much the knob overshoots.

number26 / 0.3

Accessibility

  • A <button role="switch"> with aria-checked: Space and Enter flip it.
  • The label is a real <label> tied to the button.
  • With reduced motion the knob simply jumps.