Inputs
Switch
Toggle control for binary on/off settings, with `role="switch"`.
<script>
import { Switch } from "@codeatlasdev/ui";
let enabled = $state(false);
</script>
<Switch label="Notifications" bind:checked={enabled} />
Without a visible label, always pass aria-label (or aria-labelledby) so the switch has an accessible name. The track is 44px wide, so it is comfortable to hit on touch screens.
Basic
Default off and on states.
Reference #050 · Pick in the gallery
Code
Disabled
Reference #051 · Pick in the gallery
Code
Without label
Provide aria-label when no visible label is rendered.
Reference #053 · Pick in the gallery
Code
Settings list
Common pattern: a row with title, helper text and a trailing switch.
Email notifications
Receive updates about your account activity.
Dark mode
Switch between light and dark appearance.
Usage analytics
Help improve the product by sharing usage data.
Reference #052 · Pick in the gallery
Code
Props
| Prop | Type | Default | Description |
|---|---|---|---|
checked | boolean | false | Bindable on/off state. |
disabled | boolean | false | Disables interaction. |
name | string | – | Native name, so the switch is in FormData on a plain form submit (value `on` when checked, absent when not). |
label | string | – | Visible label rendered beside the switch. |
aria-label | string | – | Accessible name used when no visible label is rendered. |
aria-labelledby | string | – | Id of an element that names the switch. Ignored when label is set. |
class | string | – | Extra classes on the wrapper. |
onchange | (checked: boolean) => void | – | Called when the state changes. |