Snippets Radio

Bootstrap 5 Responsive Toggle Switch (Segmented Control)

Segmented radio-button toggle switches that stay accessible and keyboard friendly, from a simple two-way choice to a full-width three-option control, with a live status line.

Bootstrap 5 No jQuery Aug 2019 4.2K views

<section class="wdw-stage">
  <div class="container" style="max-width:640px">
    <div class="wdw-card p-4 p-md-5">
      <span class="wdw-eyebrow">Preferences</span>
      <h1 class="wdw-heading h3 mt-1 mb-4">Responsive toggle switches</h1>

      <fieldset class="mb-4">
        <legend class="h6 fw-semibold mb-2">Is this toggle switch awesome?</legend>
        <div class="ts" role="radiogroup">
          <input type="radio" class="btn-check" name="awesome" id="aw1" value="good" checked>
          <label class="ts-opt" for="aw1">Pretty good</label>
          <input type="radio" class="btn-check" name="awesome" id="aw2" value="yes">
          <label class="ts-opt" for="aw2">100% yes</label>
        </div>
      </fieldset>

      <fieldset class="mb-4">
        <legend class="h6 fw-semibold mb-2">Billing cycle</legend>
        <div class="ts ts-block">
          <input type="radio" class="btn-check" name="billing" id="b1" value="monthly" checked>
          <label class="ts-opt" for="b1">Monthly</label>
          <input type="radio" class="btn-check" name="billing" id="b2" value="yearly">
          <label class="ts-opt" for="b2">Yearly <span class="badge text-bg-success rounded-pill ms-1">-20%</span></label>
        </div>
      </fieldset>

      <fieldset class="mb-4">
        <legend class="h6 fw-semibold mb-2">Layout density</legend>
        <div class="ts ts-block">
          <input type="radio" class="btn-check" name="density" id="d1" value="comfortable">
          <label class="ts-opt" for="d1">Comfortable</label>
          <input type="radio" class="btn-check" name="density" id="d2" value="default" checked>
          <label class="ts-opt" for="d2">Default</label>
          <input type="radio" class="btn-check" name="density" id="d3" value="compact">
          <label class="ts-opt" for="d3">Compact</label>
        </div>
      </fieldset>

      <p class="mb-0 small wdw-muted rounded-3 bg-body-tertiary px-3 py-2" role="status" aria-live="polite" id="ts-status"></p>
    </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.