Snippets Radio

Bootstrap 5 Toggle Radio Buttons with Labels

Two groups of pill-shaped radio toggles where the label is the whole click target. The selected option gets a tinted background and a filled dot.

Bootstrap 5 No jQuery Aug 2019 2.2K views

<section class="wdw-stage tr-root" id="trRoot">
  <div class="container" style="max-width:920px">
    <div class="text-center mb-4">
      <span class="wdw-eyebrow mb-2">Preferences</span>
      <h2 class="wdw-heading h2">Pick one from each group</h2>
    </div>
    <div class="row g-4">
      <div class="col-md-6">
        <div class="wdw-card p-4 p-md-5 h-100">
          <fieldset>
            <legend class="h6 fw-bold mb-3">Billing cycle</legend>
            <div class="d-flex flex-wrap gap-2">
              <input type="radio" class="btn-check" name="tr1" id="tr1a" autocomplete="off" value="monthly" checked><label class="btn btn-outline-primary rounded-pill px-4" for="tr1a">Monthly</label>
              <input type="radio" class="btn-check" name="tr1" id="tr1b" autocomplete="off" value="yearly"><label class="btn btn-outline-primary rounded-pill px-4" for="tr1b">Yearly <span class="badge text-bg-success rounded-pill">-20%</span></label>
            </div>
          </fieldset>
          <div class="mt-4 pt-4 border-top" aria-live="polite">
            <div class="d-flex align-items-baseline gap-2"><span class="display-5 fw-bold text-body-emphasis" id="trPrice">$24</span><span class="wdw-muted">/ month</span></div>
            <p class="small wdw-muted mb-0" id="trNote">Billed monthly. Cancel anytime.</p>
          </div>
        </div>
      </div>
      <div class="col-md-6">
        <div class="wdw-card p-4 p-md-5 h-100">
          <fieldset>
            <legend class="h6 fw-bold mb-3">Theme</legend>
            <div class="d-flex flex-wrap gap-2">
              <input type="radio" class="btn-check" name="tr2" id="tr2a" autocomplete="off" value="light"><label class="btn btn-outline-primary rounded-pill px-4" for="tr2a"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4"/></svg> Light</label>
              <input type="radio" class="btn-check" name="tr2" id="tr2b" autocomplete="off" value="dark"><label class="btn btn-outline-primary rounded-pill px-4" for="tr2b"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8z"/></svg> Dark</label>
            </div>
          </fieldset>
          <div class="mt-4 pt-4 border-top">
            <p class="mb-1 fw-semibold text-body-emphasis">Interface appearance</p>
            <p class="small wdw-muted mb-0" id="trThemeNote">Switches this preview between light and dark.</p>
          </div>
        </div>
      </div>
    </div>
  </div>
</section>

Built on Bootstrap 5.3.8 with plain JavaScript — no jQuery. Supports light and dark mode via data-bs-theme.

Free to use in personal and commercial projects under the MIT license.