Snippets Checkbox

Bootstrap 5 Custom Checkbox Switches

A preference list of city choices as large rows with sliding switches, highlighting selected rows and counting the total.

Bootstrap 5 No jQuery Aug 2019 2K views

<section class="wdw-stage">
  <div class="container" style="max-width:460px">
    <div class="wdw-card p-4 p-md-5" role="group" aria-labelledby="flTitle">
      <span class="wdw-eyebrow">Preferences</span>
      <h1 class="h3 wdw-heading mb-1" id="flTitle">Do you like…</h1>
      <p class="text-body-secondary mb-4">Pick every city you would visit again.</p>
      <div class="d-grid gap-2">
      <label class="fl-row d-flex align-items-center justify-content-between gap-3 p-3 rounded-4" for="city0">
        <span><span class="fw-semibold d-block">Paris</span><span class="small text-body-secondary">Croissants and long walks</span></span>
        <span class="form-check form-switch fl-sw m-0 p-0"><input class="form-check-input fl-switch" type="checkbox" role="switch" id="city0" checked></span>
      </label>
      <label class="fl-row d-flex align-items-center justify-content-between gap-3 p-3 rounded-4" for="city1">
        <span><span class="fw-semibold d-block">London</span><span class="small text-body-secondary">Rain, tea and theatre</span></span>
        <span class="form-check form-switch fl-sw m-0 p-0"><input class="form-check-input fl-switch" type="checkbox" role="switch" id="city1"></span>
      </label>
      <label class="fl-row d-flex align-items-center justify-content-between gap-3 p-3 rounded-4" for="city2">
        <span><span class="fw-semibold d-block">New York</span><span class="small text-body-secondary">The city that never sleeps</span></span>
        <span class="form-check form-switch fl-sw m-0 p-0"><input class="form-check-input fl-switch" type="checkbox" role="switch" id="city2"></span>
      </label>
      </div>
      <p class="small text-body-secondary mt-4 mb-0" aria-live="polite"><span id="flCount">1</span> of 3 selected</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.