ToggleSwitch
Settings, on or off.
About
On/off switch for settings. Navy means on. A hidden native checkbox with role="switch" carries focus, Space and aria-checked; the drawn track is what the user sees. A description line explains the consequence of turning the setting on, and iconOn / iconOff paint a glyph on the knob. Form-associated: posts name=value while on.
Usage
Basic
A hidden native checkbox with role="switch" carries focus, Space toggling and aria-checked; the drawn track is what the user sees. Navy means on.
Sizes and descriptions
md is a 38 by 21 track and sm is 30 by 17. A description explains the consequence of turning the setting on and is wired through aria-describedby.
Knob icons and label side
icon-off and icon-on paint a Font Awesome glyph on the moving knob, spelled as on sui-toggle-button. label-pos="start" moves the label before the track, which is what a settings table needs; under dir="rtl" the label, the track and the knob all mirror.
States
required means the switch must be on for the form to be valid. An error replaces the help line and paints a danger ring inside the track; invalid draws the same ring without a message, as on sui-checkbox. Both set aria-invalid on the input.
Read-only
readonly keeps the switch named and in the tab order, a click or Space changes nothing, and it still posts.
In a form
An on switch posts name=value, where value defaults to "on". An off switch posts nothing, the way a native checkbox does, and a disabled one is barred from submission.
Events
suiChange carries the new on state. The switch writes checked before it emits, so a framework binding stays in step.
Keyboard
| Key | Action |
|---|---|
| Tab | Moves to the switch; the track shows the focus ring. |
| Space | Flips the switch and fires suiChange. |
| Enter | Submits the surrounding form, as a native checkbox does. |
API
<sui-toggle-switch>
Properties
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
checked | checked | boolean | false | On state. Mutable: the element toggles it on user input, then emits suiChange. Reflected, so sui-toggle-switch[checked] matches the switch as it is now. |
description | description | stringstring | undefined | Secondary line under the label explaining the consequence; wired through aria-describedby. | |
disabled | disabled | boolean | false | Disables the switch. A disabled switch posts nothing and never holds the form. |
error | error | stringstring | undefined | Error message under the switch; replaces the help line and sets aria-invalid. | |
help | help | stringstring | undefined | Help text under the switch. Replaced by error when set. | |
iconOff | icon-off | stringstring | undefined | Font Awesome class shown while off, e.g. "fa-solid fa-sun". | |
iconOn | icon-on | stringstring | undefined | Font Awesome class shown while on, e.g. "fa-solid fa-moon". It travels on the knob. A style prefix is added when omitted (fa-solid). Spelled as on sui-toggle-button. | |
invalid | invalid | boolean | false | Danger ring on the track without a message, for a form that draws its summary elsewhere, as on sui-checkbox. error draws the same ring with its message line. Both set aria-invalid. |
label | label | stringstring | undefined | Visible label. | |
labelPos | label-pos | "end" | "start" | 'end' | Where the label sits in reading order: end puts it after the track and start before it, which is what a settings table needs; under dir="rtl" both mirror with the text. Any other value reads as end. The knob travels toward the inline-end when on. |
name | name | stringstring | undefined | Form control name. Reflected: the form entry is built from the content attribute. | |
readOnly | readonly | boolean | false | Display only: the switch keeps its name and its tab stop but a click or Space changes nothing, and it still posts. Neither a read-only nor a disabled switch holds the form on valueMissing. |
required | required | boolean | false | The switch must be on for the surrounding form to be valid, as a consent switch is. |
size | size | "md" | "sm" | 'md' | Track size: md 38 by 21 (default), sm 30 by 17. |
value | value | string | 'on' | Value posted with the form while on; defaults to "on". |
Events
| Event | Detail | React | Vue | Description |
|---|---|---|---|---|
suiChange | boolean | onSuiChange | @sui-change | Fires on toggle; detail is the new on state. |
Methods
| Method | Signature | Description |
|---|---|---|
setFocus() | setFocus() => Promise<void> | Moves keyboard focus to the (hidden) native input, as el.focus() does; the track shows the focus ring. |
Theming
Every design token this element can render with, read from its own stylesheets and the ones it imports. Set a token on :root or on any ancestor and every use below follows it. The values shown are the ones in the theme you are viewing. The list is read per stylesheet, so an element that imports a shared drawing module lists that module's tokens too, whether or not it paints with all of them.
Color11
Typography1
Motion2
Every name above is listed with its value and its role in Foundations.