Switch
A toggle for settings that apply immediately.
Full screen Code
Installation
Copy code
npx @mielui/svelte add switchyarn dlx @mielui/svelte add switchbunx @mielui/svelte add switchUsage
Bind checked to read or set the state. label names the switch and toggles it when clicked, and description is announced with it. Without a visible label, pass aria-label. Set name and value to include the switch in a form submission while it is on.
<script lang="ts">
import { Switch } from '@mielui/svelte/components/switch';
let enabled = $state(false);
</script>
<Switch bind:checked={enabled} label="Notifications" />Bind element to reach the underlying button, for example to focus it.
Examples
Basic
Full screen Code
With description
Full screen Code
Disabled
Full screen Code
API reference
Switch
Toggles a boolean value.
checkedBindablebooleanWhether it is on. Bindable.
Default
falselabelstringVisible label linked to the control.
descriptionstringSupporting text under the label, announced with the control.
elementBindableHTMLButtonElementBindable reference to the DOM element.
pnpm dlx @mielui/svelte add switch