Switch component overview
Use a Checkbox when the choice is part of a form that requires explicit submission, or when multiple items can be selected at once. Use a Switch when the action takes immediate effect.
When to use
Use a switch when
- Toggling a single setting that takes effect immediately
- The on/off state directly controls a feature, mode, or preference
- The action does not require a separate confirmation or form submission
- You need a compact, recognizable binary control
Do not use a switch when
- The setting only takes effect after the user clicks a Save or Submit button
- Multiple related options need to be selected together (use checkboxes)
- The action is irreversible and needs a confirmation step
- The label text does not clearly describe the result of toggling
- The user must turn it on to continue, such as accepting terms (use
bq-checkbox) - The user must pick one of several named options (use
bq-radio-group)
Anatomy
Switch component anatomy
inner-label is set to icon, check and X marks appear inside the track to reinforce the on/off state.
Design guidelines
States
A switch has four interactive states: default (off), checked (on), focused, and disabled. Hover adds a subtle background whenbackground-on-hover is enabled. The disabled state prevents all interaction and dims the control to signal it is unavailable.
Always pair a switch with a visible text label unless the context makes the purpose unmistakably clear (for example, a dark-mode toggle adjacent to sun and moon icons). Unlabeled switches are inaccessible by default.
Inner label
1
Default (no inner label)
The track contains only the sliding dot. This is the most compact presentation and works well in dense settings panels.
2
Icon inner label
Set
inner-label="icon" to show a check icon when ON and an X icon when OFF inside the track. This adds a secondary visual reinforcement of the state without relying on color alone.3
Custom icon slots
Replace the default icons by providing content to the
icon-on and icon-off named slots alongside inner-label="icon". Use this for domain-specific icons such as a moon/sun pair for a dark-mode toggle.Label position
By default, the label appears to the right of the control. Setreverse-order to move it to the left — useful in right-to-left layouts or when a consistent label-first alignment is required across a settings list.
Usage
Default
The default switch provides a basic on/off toggle functionality, allowing users to control a binary state effortlessly.Checked
Use thechecked attribute to set the initial state of the toggle as ON. This is ideal when you want the switch to start in an activated position.
Options
Disabled
The disabled switch prevents user interaction, making it visually clear that the toggle functionality is not currently available or applicable. Use thedisabled attribute to enable this type of switch.
With inner label
Enhance user understanding by incorporating an inner label that provides context about the current state of the switch. Use theinner-label="icon" attribute to activate this variant.
Allowed inner-label values: default (default), icon.
Custom icons
Use theicon-on and icon-off slots to replace the default check and X marks. The slots render inside the track when inner-label="icon" is enabled.
Reverse order
The reverse order switch alters the visual arrangement, placing the toggle on the opposite side for a customizable user interface by adding thereverse-order attribute.
Full width
Usefull-width with reverse-order and justify-content="space-between" to build standard settings-list rows where the label is on the left and the toggle sits flush to the right edge.
Allowed justify-content values: start (default), end, center, flex-start, flex-end, left, right, space-between, space-around, space-evenly, stretch, normal, inherit, initial.
Form integration
bq-switch participates in native forms through ElementInternals. A checked switch submits "on" for its name; an unchecked switch is omitted from FormData.
A required switch blocks form submission until it is ON, and form-validation-message sets the text of the native validation bubble. Set required only when the form cannot continue unless the switch is ON.
Best practices
DoUse concise, present-tense labels that clearly describe the result of the switch being on. “Enable notifications” or “Dark mode” communicate the outcome at a glance.
Don’tUse vague labels like “Toggle” or “On/Off”. Users should not need to think about what the switch controls — the label must describe the setting itself.
DoApply the switch’s effect immediately without requiring a submit action. Use this pattern for preferences that take effect in real time — dark mode, notifications, or feature flags.
Don’tUse a switch when the change only takes effect after the user clicks a Save button. If the state is not immediately applied, use a checkbox inside a form instead.
DoUse
inner-label="icon" to supplement the color change with a shape cue (check / X). This improves the control for users with color vision deficiencies who cannot rely on brand color alone.Don’tRely solely on the track color to communicate the ON state. Always ensure that at least one additional cue — dot position or icon — distinguishes the two states.
DoPlace the label directly adjacent to the switch and keep the pairing stable across the list. Consistent label position helps users scan a settings panel without searching for the control.
Don’tDon’t change the label text based on state (for example, “Enabled” when on and “Disabled” when off). The label should always describe the setting; the control itself communicates the current state.
DoUse
bq-checkbox with required for consent and bq-radio-group with required for a required choice between named options.Don’tDon’t use a required switch as a consent or choose-one control. A switch that must be ON is a checkbox in disguise, and users read an OFF switch as a valid answer.
Accessibility
bq-switch renders a native <input type="checkbox" role="switch"> inside its shadow DOM, which ensures that assistive technologies correctly announce the control as a switch with an on/off state.
Keyboard interaction
The native
<input type="checkbox" role="switch"> handles these keys. A disabled switch ignores Space.
Rules
Developer responsibilities
- You must provide a visible text label via the default slot. The switch derives its accessible name from the
nameprop viaaria-labelon the native<input>; the visible slot text is not automatically wired to the control. To make the visible label the accessible name, you should usearia-labelledbyon the host element pointing to the associated label element. - You must set the
nameattribute (required) to participate in form submissions and to give the control a machine-readable identifier. - When the switch is
disabled, it is excluded from the tab order and does not respond to keyboard or pointer events. You should communicate the reason for disabling through surrounding text. - You must tell users before submit that a required switch has to be ON. The validation bubble only appears after a failed submit.
- The
bqChangeevent is cancelable. Callingevent.preventDefault()inside abqChangehandler prevents the switch from updating its visual state, which is useful when you need to confirm a change before applying it. - You should use
vFocus(),vBlur(), andvClick()instead of the globalelement.focus(),element.blur(), andelement.click()to interact with the native input correctly across Shadow DOM boundaries.
API reference
Properties
Invalid combinations
No invalid prop combinations.Methods
Events
Slots
Shadow parts
CSS custom properties
Resources
Interactive playground
Explore switch variants and states in Storybook
Source code
View the component source on GitHub