Skip to content

Switch

A switch for instant on/off settings, built on a native <input type="checkbox" role="switch"> so screen readers announce on/off and the value participates in forms.

<script>
import Switch from "@invisible-ui/svelte/Switch.svelte";
</script>
PropTypeDefaultDescription
label *string—Accessible, visible label; override with children.
hideLabelbooleanfalseVisually hide the label while keeping it as the accessible name. The label text is always required.
checkedbooleanfalseOn/off state.
disabledbooleanfalseDisable the control.
namestring | undefinedundefinedForm field name; the value is submitted under it when on.
valuestring"on"Value submitted with the form when on.
requiredbooleanfalseMark the control required for native form validation.
onOffbooleanfalseShow ON/OFF text inside the track (a wider, labelled variant).
onTextstring | undefinedundefinedText shown in the track when on / off (only with onOff).
offTextstring | undefinedundefined
onCheckedChange((c: boolean) => void) | undefinedundefinedCalled whenever the value changes.
  • Native <input type="checkbox" role="switch">: the browser provides Space activation, focus and form participation, and screen readers announce “on”/“off”.
  • The thumb moves along the inline axis, so in right-to-left text it stays on the track and sits at the end edge, the left one, when on.
  • A label is required; the native input is wrapped in a <label>, so the visible text names the control and clicking it toggles the switch.
<Switch label="Wi-Fi" checked onCheckedChange={(on) => setWifi(on)} />

Themeable via --ds-switch-*.