Switch
Switches allow users to make a single immediate binary decision (yes/no, on/off etc.).
Also known as: on/off switch, slide toggle, toggle, toggle button, toggle switch
<bolt-switch
label="Switch label"
></bolt-switch>
<bolt-switch
instructionaltext="Turn on/off email notifications"
label="Email notifications"
></bolt-switch>
<bolt-switch
error="This field is required"
required
label="Switch label"
></bolt-switch>
<bolt-switch
disabled
label="Switch label"
></bolt-switch>
<bolt-switch
label="Non-required switch"
optionaltext="hide"
></bolt-switch>
Help text body content
<bolt-switch label="Switch label">
<bolt-contextual-help
slot="help"
heading="Help text heading"
>
<p>Help text body content</p>
</bolt-contextual-help>
</bolt-switch>
Elements
Permalink to "Elements"<bolt-switch>
Permalink to "<bolt-switch>"properties
Permalink to "properties"The <bolt-switch> custom element must include one of these three parameters (required):
label: The label text for the input. This generates a visible<label>element associated with the underlying<input>element.arialabel: Sets thearia-labelattribute of the underlying<input>element.arialabelledby: Sets thearia-labelledbyattribute of the underlying<input>element.
Additionally, The <bolt-switch> element supports the following parameters:
checked(optional)- If present, the field is checked.
datatestinput(optional)- Optional property to configure the
[data-test]value on the underlying<input>element. - default:
"input"
- Optional property to configure the
disabled(optional)- If present, disables rendered interactive elements.
error(optional)- The error message to display below the input.
- Should not be used when component is
disabled. For slotted field error see switch with error slot
instructionaltext(optional)- The instructional text to display below the input.
- This should be used to inform users about Switch effects.
invalid(optional)- If present, renders underlying input semantically invalid to screen readers.
optionaltext(optional)show(default) orhide. Use to remove the "(optional)" text from non-required fields.
required(optional)- If present, the field is required. Fields that are not required will show "(optional)".
value(optional)- The value for the input, which must be a string. The
valueattribute will not accept an object.
- The value for the input, which must be a string. The
events
Permalink to "events"blurchange: fires when toggledfocusinput: fires when toggled
Internals
Permalink to "Internals"Test selectors
Permalink to "Test selectors"[data-test="input"]targets the primary <input> element.- Configurable via the
datatestinputproperty.
- Configurable via the
General guidelines
Permalink to "General guidelines"- Switches allow users to make a single binary decision (yes/no, on/off etc.) with an immediate effect.
- There is no indeterminate state of a Switch, it must be set to either selected (on) or unselected (off)
- A Switch should always a have label or surrounding context.
When to use
Permalink to "When to use"- When a user can make a binary decision AND the input can be recorded or updated immediately.
When not to use
Permalink to "When not to use"- Avoid if a submit Button is needed to apply or save a selection.
- Avoid if there are more than two available choices.
- Avoid if the choices are not binary. (Example: Would you like chocolate or no ice cream?)
When to use something else
Permalink to "When to use something else"- Consider Checkbox when there are more than 2 related options, multiple items can be selected AND the result needs saving or submitted.
- Consider Radio button or Select when there are more than 2 related options, only a single item can be selected AND the result needs saving or submitted.
- Consider Radio button for a set of options requiring a single choice that is not binary or has unequal states.
- If users need to confirm a statement, consider a Checkbox.
Do
- Keep the same label text regardless of the Switch state.
- Use a concise label to explain what is toggling on and off.
- Use instructional text to inform users about Switch effects.
- Use Switch for a binary choice that can be either active or inactive.
- Place Switch labels close enough for intuitive association.
Don't
- Don't change the label when the Switch changes state.
- Don't use alternative styling to represent Switch functionality.
- Don't use a Switch if additional steps are required for changes to take effect.
- Don't use a Switch as a replacement for a Checkbox.
- Don't add text or Icons into the Switch handle or track.
- Don't add state labels like "on" and "off" to a Switch. The label wording should imply clearly what each state represents. Otherwise use instructional text for further clarity.
- Don't truncate label text, instead let it wrap to form another line.
Content guidelines
Permalink to "Content guidelines"- Labels should be in sentence case with no ending punctuation; aim for six words or fewer.
- If a label is more than six words, consider adding necessary context in Contextual Help or instructional text outside the Switch label.
- Avoid using complex questions and long text.
Accessibility compliance
Permalink to "Accessibility compliance"-
WCAG 2.2 Compliant
-
JAWS 2025 Tested
-
NVDA 2025 Tested
-
VoiceOver Tested
-
Keyboard Tested
-
aXe Tested
Assistive technology behavior
Permalink to "Assistive technology behavior"- Spacebar key toggles the switch state between
onandoff.
All Bolt components have gone through accessibility testing, but please keep our accessibility guidelines in mind.