Forms
Switch
A toggle switch for boolean values. Supports labels, descriptions, checked/unchecked icons, colors, sizes, and loading states.
Playground
Experiment with different props in real-time.
Toggle this feature on or off
Basic Usage
<script lang="ts">
import { Switch } from 'sv5ui';
let enabled = $state(false);
</script>
<Switch bind:checked={enabled} />Label & Description
Add context with label and description props.
Receive alerts when someone mentions you.
Use dark theme across the application.
Help us improve by sending anonymous usage data.
<Switch
bind:checked={notifications}
label="Push Notifications"
description="Receive alerts when someone mentions you."
/>
<Switch
bind:checked={darkMode}
label="Dark Mode"
description="Use dark theme across the application."
/>
<Switch
bind:checked={analytics}
label="Usage Analytics"
description="Help us improve by sending anonymous usage data."
/>Sizes
5 sizes.
<Switch size="xs" label="Extra Small" bind:checked={xs} />
<Switch size="sm" label="Small" bind:checked={sm} />
<Switch size="md" label="Medium" bind:checked={md} />
<Switch size="lg" label="Large" bind:checked={lg} />
<Switch size="xl" label="Extra Large" bind:checked={xl} />Colors
8 semantic color schemes.
<Switch color="primary" label="Primary" checked />
<Switch color="secondary" label="Secondary" checked />
<Switch color="tertiary" label="Tertiary" checked />
<Switch color="success" label="Success" checked />
<Switch color="warning" label="Warning" checked />
<Switch color="error" label="Error" checked />
<Switch color="info" label="Info" checked />
<Switch color="surface" label="Surface" checked />With Icons
Show different icons for checked/unchecked states.
<Switch
bind:checked={wifi}
label="Wi-Fi"
checkedIcon="lucide:wifi"
uncheckedIcon="lucide:wifi-off"
/>
<Switch
bind:checked={sound}
label="Sound"
checkedIcon="lucide:volume-2"
uncheckedIcon="lucide:volume-x"
/>
<Switch
bind:checked={visibility}
label="Visibility"
checkedIcon="lucide:eye"
uncheckedIcon="lucide:eye-off"
/>Loading
<Switch label="Syncing settings..." loading checked />
<Switch label="Connecting..." loading />Disabled
<Switch label="Enabled (disabled)" checked disabled />
<Switch label="Disabled (disabled)" disabled />UI Slots
Use the ui prop to override classes on internal elements.
| Slot | Description |
|---|---|
root | Outermost wrapper |
base | Switch track |
container | Track container |
thumb | Sliding thumb |
icon | Icon inside thumb |
wrapper | Label/description wrapper |
label | Label text |
description | Description text |
With overridden slot classes
<Switch
label="Custom Styled"
description="With overridden slot classes"
checked
ui={{
base: 'bg-success',
thumb: 'bg-white shadow-lg',
label: 'font-bold tracking-wide',
description: 'italic'
}}
/>Snippets
| Snippet | Description |
|---|---|
labelSlot | Custom label rendering |
descriptionSlot | Custom description rendering |
Props
| Prop | Type | Default |
|---|---|---|
checked | boolean | false |
onCheckedChange | (checked) => void | - |
color | ColorType | 'primary' |
size | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'md' |
label | string | - |
description | string | - |
checkedIcon | string | - |
uncheckedIcon | string | - |
loading | boolean | false |
loadingIcon | string | icons.loading |
disabled | boolean | false |
required | boolean | false |
id | string | - |
name | string | - |
value | string | - |
ref | HTMLElement | null | null |
class | string | - |
ui | Record<Slot, Class> | - |