Snippets Buttons

Bootstrap 5 Toggle Switch Styles

A grid of eight toggle switch styles, from a classic switch to outline, icon, bouncing and text variants, each with a live on and off badge.

Bootstrap 5 No jQuery Mar 2020 2.2K views

<section class="wdw-stage">
  <div class="container" style="max-width:1100px">
    <div class="mb-4 text-center">
      <span class="wdw-eyebrow">Controls</span>
      <h2 class="wdw-heading h2 mt-1 mb-2">Toggle switches</h2>
      <p class="wdw-muted mb-0">Eight distinct toggle styles. Each one is a real checkbox or radio underneath.</p>
    </div>
    <div class="row row-cols-1 row-cols-sm-2 row-cols-lg-4 g-3">
      <div class="col">
        <div class="wdw-card-sm tg-cell p-4 h-100 d-flex flex-column gap-3">
          <div class="d-flex justify-content-between align-items-center gap-2"><span class="small fw-bold text-body-emphasis">Default switch</span><span class="badge rounded-pill tg-state" id="st1" data-on="On" data-off="Off">On</span></div>
          <label class="tg-hit d-flex align-items-center gap-3 flex-grow-1 " for="sw1"><span class="form-check form-switch tg-wrap p-0 m-0"><input class="form-check-input tg-input tg-lg" type="checkbox" role="switch" id="sw1" aria-describedby="st1" checked></span><span class="fw-medium">Notifications</span></label>
        </div>
      </div>
      <div class="col">
        <div class="wdw-card-sm tg-cell p-4 h-100 d-flex flex-column gap-3">
          <div class="d-flex justify-content-between align-items-center gap-2"><span class="small fw-bold text-body-emphasis">Sun and moon</span><span class="badge rounded-pill tg-state" id="st2" data-on="On" data-off="Off">Off</span></div>
          <label class="tg-hit d-flex align-items-center gap-3 flex-grow-1 " for="sw2"><span class="form-check form-switch tg-wrap p-0 m-0"><input class="form-check-input tg-input tg-lg tg-theme" type="checkbox" role="switch" id="sw2" aria-describedby="st2"></span><span class="fw-medium">Dark mode</span></label>
        </div>
      </div>
      <div class="col">
        <div class="wdw-card-sm tg-cell p-4 h-100 d-flex flex-column gap-3">
          <div class="d-flex justify-content-between align-items-center gap-2"><span class="small fw-bold text-body-emphasis">Yes and no</span><span class="badge rounded-pill tg-state" id="st3" data-on="On" data-off="Off">Off</span></div>
          <label class="tg-hit d-flex align-items-center gap-3 flex-grow-1 " for="sw3"><span class="form-check form-switch tg-wrap tg-yn p-0 m-0 position-relative"><input class="form-check-input tg-input tg-yn-input" type="checkbox" role="switch" id="sw3" aria-describedby="st3"><span class="tg-yn-n" aria-hidden="true">No</span><span class="tg-yn-y" aria-hidden="true">Yes</span></span><span class="fw-medium">Auto-renew</span></label>
        </div>
      </div>
      <div class="col">
        <div class="wdw-card-sm tg-cell p-4 h-100 d-flex flex-column gap-3">
          <div class="d-flex justify-content-between align-items-center gap-2"><span class="small fw-bold text-body-emphasis">Check thumb</span><span class="badge rounded-pill tg-state" id="st4" data-on="On" data-off="Off">On</span></div>
          <label class="tg-hit d-flex align-items-center gap-3 flex-grow-1 " for="sw4"><span class="form-check form-switch tg-wrap p-0 m-0"><input class="form-check-input tg-input tg-lg tg-check" type="checkbox" role="switch" id="sw4" aria-describedby="st4" checked></span><span class="fw-medium">Public profile</span></label>
        </div>
      </div>
      <div class="col">
        <div class="wdw-card-sm tg-cell p-4 h-100 d-flex flex-column gap-3">
          <div class="d-flex justify-content-between align-items-center gap-2"><span class="small fw-bold text-body-emphasis">Billing period</span><span class="badge rounded-pill tg-state" id="st5" data-on="On" data-off="Off">Monthly</span></div>
          <div class="tg-seg d-flex p-1 rounded-pill bg-body-secondary" role="radiogroup" aria-label="Billing period" aria-describedby="st5">
            <input class="btn-check tg-input" type="radio" name="bill" id="sw5a" data-state="Monthly" checked><label class="btn rounded-pill flex-fill" for="sw5a">Monthly</label>
            <input class="btn-check tg-input" type="radio" name="bill" id="sw5b" data-state="Yearly"><label class="btn rounded-pill flex-fill" for="sw5b">Yearly</label>
          </div>
          <p class="small wdw-muted mb-0">Yearly billing saves 20%.</p>
        </div>
      </div>
      <div class="col">
        <div class="wdw-card-sm tg-cell p-4 h-100 d-flex flex-column gap-3">
          <div class="d-flex justify-content-between align-items-center gap-2"><span class="small fw-bold text-body-emphasis">Settings row</span><span class="badge rounded-pill tg-state" id="st6" data-on="On" data-off="Off">On</span></div>
          <label class="tg-hit tg-row d-flex align-items-center gap-3 flex-grow-1 border rounded-4 p-3" for="sw6">
            <span class="flex-grow-1 lh-sm"><span class="d-block fw-semibold">Email alerts</span><span class="d-block small wdw-muted">Weekly summary, Mondays</span></span>
            <span class="form-check form-switch tg-wrap p-0 m-0 flex-shrink-0"><input class="form-check-input tg-input tg-lg" type="checkbox" role="switch" id="sw6" aria-describedby="st6" checked></span>
          </label>
        </div>
      </div>
      <div class="col">
        <div class="wdw-card-sm tg-cell p-4 h-100 d-flex flex-column gap-3">
          <div class="d-flex justify-content-between align-items-center gap-2"><span class="small fw-bold text-body-emphasis">Selectable card</span><span class="badge rounded-pill tg-state" id="st7" data-on="Selected" data-off="Not selected">Not selected</span></div>
          <input class="btn-check tg-input" type="checkbox" id="sw7" aria-describedby="st7">
          <label class="tg-pick position-relative d-block flex-grow-1 border rounded-4 p-3" for="sw7">
            <span class="tg-badge position-absolute top-0 end-0 m-2 rounded-circle d-inline-flex align-items-center justify-content-center"><svg class="tg-tick" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg></span>
            <span class="wdw-icon mb-2"><svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 3l2.7 5.6 6.1.9-4.4 4.3 1 6.1L12 17l-5.4 2.9 1-6.1L3.2 9.500l6.100-.9z"/></svg></span>
            <span class="d-block fw-semibold">Priority support</span>
            <span class="d-block small wdw-muted">Replies in 2 hours</span>
          </label>
        </div>
      </div>
      <div class="col">
        <div class="wdw-card-sm tg-cell p-4 h-100 d-flex flex-column gap-3">
          <div class="d-flex justify-content-between align-items-center gap-2"><span class="small fw-bold text-body-emphasis">Toggle button</span><span class="badge rounded-pill tg-state" id="st8" data-on="Following" data-off="Not following">Not following</span></div>
          <input class="btn-check tg-input" type="checkbox" id="sw8" aria-describedby="st8">
          <label class="btn btn-outline-primary rounded-pill tg-follow align-self-start" for="sw8"><span class="tg-f-off">Follow</span><span class="tg-f-on"><svg class="tg-tick" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg>Following</span></label>
          <p class="small wdw-muted mb-0">One button that flips its own state.</p>
        </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.