On this page
Buttons
A command is a <button>. A toggle that should
persist or submit is a checkbox or radio with
.btn-check and a <label class="btn">.
There is no data-bs-toggle="button" and no script that
sets aria-pressed. A price-toggle recipe that uses this
pattern lives on
Composed examples.
| What runs it | JavaScript | |
|---|---|---|
| Bootstrap 5.3 | Button plugin. It toggles .active and aria-pressed on a button. | 1.4 KB gzip |
| This repo | checkbox or radio with .btn-check and a label.btn | 0 KB |
| Avoid |
|
|---|
How it works
-
.btn-checkvisually hides the input. The label is the hit target and takes the button look. The input stays in the accessibility tree and in the form. -
Checkbox groups are additive. Radio groups share a
nameso one choice is exclusive. -
State is
checked. Do not adddata-bs-toggle="button"or toggle.activefrom script. -
Ordinary
.btncommand buttons are unchanged. They still usecommand/commandforto open a dialog or popover.
Checkbox
Each label is a toggle. Both can stay on.
<fieldset>
<legend class="visually-hidden">Notifications</legend>
<input type="checkbox" class="btn-check" id="buttons-email" autocomplete="off" checked>
<label class="btn btn-outline-primary" for="buttons-email">Email</label>
<input type="checkbox" class="btn-check" id="buttons-sms" autocomplete="off">
<label class="btn btn-outline-primary" for="buttons-sms">SMS</label>
</fieldset> Radio
One name, one selected. The checked label uses the button active look.
<fieldset>
<legend class="visually-hidden">Plan</legend>
<input type="radio" class="btn-check" name="buttons-plan" id="buttons-monthly" autocomplete="off" checked>
<label class="btn btn-outline-primary" for="buttons-monthly">Monthly</label>
<input type="radio" class="btn-check" name="buttons-plan" id="buttons-yearly" autocomplete="off">
<label class="btn btn-outline-primary" for="buttons-yearly">Yearly</label>
</fieldset> Accessibility
The input stays in the tree. .btn-check visually hides it; the label is the hit target. Do not add display: none on the input.
Group radios with the same name. A checkbox group can sit in a <fieldset> with a <legend>.
Do not put role="button" on the label. It is already a label for the input.
Browser support
| No script | Polyfill | No fallback |
|---|---|---|
.btn-check is CSS on a native checkbox or radio. Chrome, Firefox, and Safari have shipped it with Bootstrap’s stylesheet. | None | None. Without this stylesheet the control is still a checkbox or radio. The label just looks like a button when .btn-check is present. |