Snippets Buttons

Bootstrap 5 Filterable List with Filter Buttons

A people directory with pill filter buttons that narrow the list by profession, row selection checkboxes and a live result count.

Bootstrap 5 No jQuery Jun 2020 2.7K views

<section class="wdw-stage">
  <div class="container" style="max-width: 760px;">
    <div class="wdw-card overflow-hidden">
      <div class="p-4 d-flex flex-wrap align-items-center justify-content-between gap-3 border-bottom">
        <div>
          <span class="wdw-eyebrow">Directory</span>
          <h1 class="h4 wdw-heading mb-0">Team members</h1>
        </div>
        <div class="d-flex flex-wrap gap-2" role="group" aria-label="Filter by profession" id="tfFilters">
          <button type="button" class="btn btn-sm btn-primary rounded-pill px-3" data-filter="all" aria-pressed="true">All <span class="badge tf-count ms-1" data-count="all">4</span></button>
          <button type="button" class="btn btn-sm btn-outline-primary rounded-pill px-3" data-filter="engineer" aria-pressed="false">Engineers <span class="badge tf-count ms-1" data-count="engineer">2</span></button>
          <button type="button" class="btn btn-sm btn-outline-primary rounded-pill px-3" data-filter="doctor" aria-pressed="false">Doctors <span class="badge tf-count ms-1" data-count="doctor">1</span></button>
          <button type="button" class="btn btn-sm btn-outline-primary rounded-pill px-3" data-filter="teacher" aria-pressed="false">Teachers <span class="badge tf-count ms-1" data-count="teacher">1</span></button>
        </div>
      </div>
      <div class="px-4 py-3 border-bottom">
        <label for="tfSearch" class="visually-hidden">Search people</label>
        <input type="search" class="form-control rounded-pill" id="tfSearch" placeholder="Search by name or company" autocomplete="off">
      </div>
      <ul class="list-group list-group-flush" id="tfList">
        <li class="list-group-item tf-row" data-role="engineer">
          <input class="form-check-input tf-check" type="checkbox" aria-label="Select William">
          <img src="https://i.pravatar.cc/96?img=12" alt="" width="48" height="48" class="tf-avatar">
          <div class="flex-grow-1"><div class="fw-bold">William Carter</div><div class="small wdw-muted">Working at Google Inc.</div></div>
          <span class="badge rounded-pill tf-badge bg-primary-subtle text-primary-emphasis"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m16 18 6-6-6-6M8 6l-6 6 6 6"/></svg> Engineer</span>
        </li>
        <li class="list-group-item tf-row" data-role="doctor">
          <input class="form-check-input tf-check" type="checkbox" aria-label="Select Mark Steve">
          <img src="https://i.pravatar.cc/96?img=32" alt="" width="48" height="48" class="tf-avatar">
          <div class="flex-grow-1"><div class="fw-bold">Mark Steve</div><div class="small wdw-muted">Doctor at Vues Hospitals</div></div>
          <span class="badge rounded-pill bg-primary-subtle text-primary-emphasis tf-badge"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 5v14M5 12h14"/></svg> Doctor</span>
        </li>
        <li class="list-group-item tf-row" data-role="teacher">
          <input class="form-check-input tf-check" type="checkbox" aria-label="Select Samso Din">
          <img src="https://i.pravatar.cc/96?img=15" alt="" width="48" height="48" class="tf-avatar">
          <div class="flex-grow-1"><div class="fw-bold">Samso Din</div><div class="small wdw-muted">Teacher at Mark School</div></div>
          <span class="badge rounded-pill bg-primary-subtle text-primary-emphasis tf-badge"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2 8l10-5 10 5-10 5zM6 10.5V16c3 2 9 2 12 0v-5.5"/></svg> Teacher</span>
        </li>
        <li class="list-group-item tf-row" data-role="engineer">
          <input class="form-check-input tf-check" type="checkbox" aria-label="Select Timothi Singla" checked>
          <img src="https://i.pravatar.cc/96?img=47" alt="" width="48" height="48" class="tf-avatar">
          <div class="flex-grow-1"><div class="fw-bold">Timothi Singla</div><div class="small wdw-muted">Software engineer at Apple Inc.</div></div>
          <span class="badge rounded-pill tf-badge bg-primary-subtle text-primary-emphasis"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m16 18 6-6-6-6M8 6l-6 6 6 6"/></svg> Engineer</span>
        </li>
      </ul>
      <div class="px-4 py-3 border-top small wdw-muted d-flex justify-content-between gap-3"><span id="tfStatus" aria-live="polite">Showing 4 of 4 people</span><span id="tfSelected" class="fw-semibold text-body-emphasis" aria-live="polite">1 selected</span></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.