Switch
An on/off toggle whose knob swells into a clear lens while it crosses the track.
Latest change Improved v3.0.19 Drawn in plain WebGL2 and without three, like Slider; it looks as it did.
- v3.0.19 Improved Drawn in plain WebGL2 and without
three, like Slider; it looks as it did. - v3.0.9 Improved A flick toggles it whichever side the knob is on, and a touch the browser takes for a scroll toggles nothing. A second finger no longer restarts the drag.
- v3.0.9 Improved On the docs, the Speed choice above the previews is this switch, orange while Quick is on.
- v1.3.8 Improved A
colorprop for the track while on. The examples are now the switch in a few colours, nothing else. - v1.3.3 Improved Examples: a settings list with a disabled switch, the three sizes and the label on either side.
- v1.3.0 New The switch of the first previews: its knob swells into clear glass as it crosses the track.
- All changes→
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-svelte@latest add https://liquidglass.pulse.city/r/switch.jsonUsage
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 UI SDK, like Slider.
API reference
| Prop | Type | Default |
|---|---|---|
checked On or off. | boolean | false |
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, | string | '#3291FF' |
theme Overrides the page theme for this switch. | 'light' | 'dark' | — |
disabled Dimmed and not interactive. | boolean | false |
lensScale Size of the travelling lens relative to the resting knob. | number | 1.55 |
refraction / knobBounce How far the lens bends the track; how much the knob overshoots. | number | 26 / 0.3 |
Accessibility
- A
<button role="switch">witharia-checked: Space and Enter flip it. - The
labelis a real<label>tied to the button. - With reduced motion the knob simply jumps.
Liquid Glass Svelte is open source and MIT licensed. If it saves you time, you can support the project.