Studio
2

Switch

Installation

pnpm dlx @mielui/svelte add switch

The visible label names the switch; descriptions are linked separately. Explicit aria-label or aria-labelledby naming takes priority. External description IDs are preserved and deduplicated, and conditional descriptions are linked only while rendered.

Usage

Use name and value to include a checked switch in form submission. Both checked and the switched alias remain bindable. A label activates the switch, and supplied ARIA relationships are preserved.

Import Switch and bind its state:

import { Switch } from '$lib/mielui/components/switch';

<Switch bind:switched={enabled} label="Notifications" />

Examples

Basic

With description

Disabled

API reference

Switch

Toggles a boolean value.

Prop Type Default
checked Bindable boolean | undefined undefined
switched Bindable boolean | undefined undefined
label string | undefined —
description string | undefined —
element Bindable HTMLButtonElement | undefined —
onclick (MouseEventHandler<HTMLButtonElement> & ((e: MouseEvent) => void)) | undefined —