Switch
A labeled on or off switch, including a disabled state.
Notifications off
Source
<script lang="ts">
import 'portal-bits/styles.css';
import 'portal-bits/tokens.css';
import type { Snippet } from 'svelte';
let { children }: { children: Snippet } = $props();
</script>
{@render children()}
<script lang="ts">
import SwitchExample from './SwitchExample.svelte';
</script>
<SwitchExample disabled={false} />
<script lang="ts">
import { Switch } from 'portal-bits';
let { disabled = false }: { disabled?: boolean } = $props();
let checked = $state(false);
</script>
<div class="row">
<Switch label="Enable notifications" bind:checked {disabled} />
<span>Notifications {checked ? 'on' : 'off'}</span>
</div>
<style>
.row {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 14px;
}
</style>
API reference
These tables list the props and snippets that Switch declares. Attributes passed through to an element or primitive are listed under Forwarded attributes, not here.
Props
| Name | Type | Default | Required | Binding | Description |
|---|---|---|---|---|---|
label | string | None | Yes | One-way | The accessible name, set as `aria-label`. |
checked | boolean | false | No | Bindable | Whether the switch is on. |
Forwarded attributes
- Bits UI `Switch.Root` props except `children` and `child`: `disabled`, `required`, `name`, `value`, `onCheckedChange`, `ref`, native button attributes, and handlers.
The primitive underneath is a Bits UI peer dependency. Its own options are documented in the Bits UI Switch documentation. Only the props listed on this page are part of the Switch contract. No data attributes are documented as stable.
Limits
- The label is not visible. Place a visible label next to the switch yourself.
- The thumb and track markup are fixed.