Switch
A button with the switch role, for settings that apply as soon as they change. Use a Checkbox when the choice is saved with a form.
Installation
Copy the command below and run it in your terminal.
Usage
Bind checked to read and set the state.
The older switched prop still works.
Click, tap, or press Space or Enter to toggle, or drag the thumb across the track and release it on either side. The thumb follows a spring, stretches while pressed or moving, and the track fills with the primary color as the thumb travels. Clicking the label toggles the switch too. With reduced motion, the thumb moves without animating.
Theme the motion with --motion-duration-switch (default 280ms, lower is faster, 0ms snaps) and --motion-switch-stretch (default 1, 0 turns the stretch off).
Examples
Basic
Notifications
With description
Disabled
Sync
Anatomy
Switch - Toggles a boolean value.
<script lang="ts"> import { Switch } from '@sivir-ui/svelte/components/switch'; let enabled = $state(true); </script> <Switch bind:checked={enabled} label="Push notifications" />