Bootstrap 5 Toggle Switch
The Bootstrap 5 Toggle Switch is a styled checkbox input that renders as a sliding on/off control using the `.form-check-input` class combined with `.form-switch` on the wrapper. It is semantically identical to a checkbox but communicates a binary state more clearly in UI contexts like settings panels, preference toggles, and feature flags. Use it when the action takes effect immediately without requiring a form submission.
Primary Class
.toggle-switchCommon Use Cases
- →Enabling or disabling email notification preferences in a user account settings page
- →Toggling dark mode on and off within an app's appearance settings panel
- →Activating or deactivating individual features in a SaaS product's feature management dashboard
- →Allowing users to opt in or out of SMS marketing messages during a checkout flow
Variants & Classes
| Variant | Description |
|---|---|
| Toggle Switch Default | Standard toggle switch with Bootstrap's default styling. |
| Toggle Switch Responsive | Responsive variant that adapts to different screen sizes. |
Code Example
<div class="mb-3">
<h6 class="mb-3">Notification Preferences</h6>
<div class="form-check form-switch mb-2">
<input class="form-check-input" type="checkbox" role="switch" id="emailNotifications" checked>
<label class="form-check-label" for="emailNotifications">Email notifications</label>
</div>
<div class="form-check form-switch mb-2">
<input class="form-check-input" type="checkbox" role="switch" id="smsNotifications">
<label class="form-check-label" for="smsNotifications">SMS notifications</label>
</div>
<div class="form-check form-switch mb-2">
<input class="form-check-input" type="checkbox" role="switch" id="weeklyDigest" checked>
<label class="form-check-label" for="weeklyDigest">Weekly digest</label>
</div>
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" id="productUpdates" disabled>
<label class="form-check-label text-muted" for="productUpdates">Product updates (unavailable on your plan)</label>
</div>
</div>Live Examples
Basic Toggle Switch
Canvas Framework Variants
The Canvas template extends Bootstrap 5 with 1,658+ component variants. Generate any of these using Canvas Builder:
- ✓Canvas Builder generated toggle switch with custom colours
- ✓Toggle Switch with interactive states
- ✓Responsive toggle switch for all screen sizes
Best Practices
Always include role="switch" for screen readers
Adding `role="switch"` to the checkbox input tells assistive technologies to announce the element as a toggle switch rather than a plain checkbox, which gives users accurate context about the control's behaviour.
Pair each toggle with a visible label
Never rely on position or colour alone to communicate state. A connected `<label>` with a matching `for` attribute ensures the toggle is operable by keyboard and correctly announced by screen readers.
Use the disabled attribute with a clear explanation
When a toggle is unavailable, add `disabled` to the input and include a short reason in the label text (such as 'upgrade required') so users understand why the control cannot be changed rather than assuming it is a bug.
Trigger immediate feedback when the state changes
Toggle switches imply instant action, so pair them with JavaScript that applies the change on the `change` event rather than waiting for a form submit button. If the action requires a server round trip, show a spinner inside or next to the toggle until confirmation arrives.