Snippets Cart

Bootstrap 5 E-commerce Filter Sidebar with Accordion

A collapsible e-commerce filter sidebar with category checkboxes, a price slider, size chips and rating options, plus a live result count.

Bootstrap 5 No jQuery Jun 2020 5.7K views

<section class="wdw-stage">
  <svg width="0" height="0" style="position:absolute" aria-hidden="true" focusable="false"><defs>
    <symbol id="flStarF" viewBox="0 0 24 24" fill="currentColor" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"><path d="m12 3 2.7 5.6 6.1.9-4.4 4.3 1 6.1L12 17l-5.4 2.9 1-6.1L3.2 9.500l6.1-.9z"/></symbol>
    <symbol id="flStarE" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"><path d="m12 3 2.7 5.6 6.1.9-4.4 4.3 1 6.1L12 17l-5.4 2.9 1-6.1L3.2 9.500l6.1-.9z"/></symbol>
  </defs></svg>
  <div class="container" style="max-width: 620px">
    <aside class="wdw-card p-3 p-md-4" aria-label="Product filters">
      <div class="d-flex justify-content-between align-items-center mb-2 px-2">
        <h2 class="wdw-heading h5 mb-0">Filters <span class="badge rounded-pill bg-primary ms-1 d-none" id="flCount">0</span></h2>
        <button type="button" class="btn btn-link btn-sm link-primary text-decoration-none fw-semibold p-0" id="flClear" style="min-height:0">Clear all</button>
      </div>
      <div class="d-flex flex-wrap gap-2 px-2 mb-2" id="flChips" aria-label="Active filters"></div>
      <div class="accordion accordion-flush" id="flAcc">
        <div class="accordion-item bg-transparent">
          <h3 class="accordion-header"><button class="accordion-button bg-transparent shadow-none fw-semibold" type="button" data-bs-toggle="collapse" data-bs-target="#flCat" aria-expanded="true" aria-controls="flCat">Categories</button></h3>
          <div id="flCat" class="accordion-collapse collapse show"><div class="accordion-body pt-0 d-grid gap-2">
            <div class="form-check d-flex align-items-center gap-2 ps-0"><input class="form-check-input ms-0 mt-0" type="checkbox" id="cat0" name="cat" checked><label class="form-check-label flex-grow-1" for="cat0">Electronics</label><span class="wdw-muted small">128</span></div>
            <div class="form-check d-flex align-items-center gap-2 ps-0"><input class="form-check-input ms-0 mt-0" type="checkbox" id="cat1" name="cat"><label class="form-check-label flex-grow-1" for="cat1">Home & Kitchen</label><span class="wdw-muted small">86</span></div>
            <div class="form-check d-flex align-items-center gap-2 ps-0"><input class="form-check-input ms-0 mt-0" type="checkbox" id="cat2" name="cat" checked><label class="form-check-label flex-grow-1" for="cat2">Fashion</label><span class="wdw-muted small">214</span></div>
            <div class="form-check d-flex align-items-center gap-2 ps-0"><input class="form-check-input ms-0 mt-0" type="checkbox" id="cat3" name="cat"><label class="form-check-label flex-grow-1" for="cat3">Sports & Outdoors</label><span class="wdw-muted small">57</span></div>
            <div class="form-check d-flex align-items-center gap-2 ps-0"><input class="form-check-input ms-0 mt-0" type="checkbox" id="cat4" name="cat"><label class="form-check-label flex-grow-1" for="cat4">Beauty</label><span class="wdw-muted small">43</span></div>
          </div></div>
        </div>
        <div class="accordion-item bg-transparent">
          <h3 class="accordion-header"><button class="accordion-button bg-transparent shadow-none fw-semibold" type="button" data-bs-toggle="collapse" data-bs-target="#flPrice" aria-expanded="true" aria-controls="flPrice">Price</button></h3>
          <div id="flPrice" class="accordion-collapse collapse show"><div class="accordion-body pt-0">
            <label for="flRange" class="form-label small wdw-muted">Up to <strong class="text-body-emphasis" id="flPriceVal">$250</strong></label>
            <input type="range" class="form-range" id="flRange" min="10" max="500" step="10" value="250">
            <div class="d-flex justify-content-between small wdw-muted"><span>$10</span><span>$500</span></div>
          </div></div>
        </div>
        <div class="accordion-item bg-transparent">
          <h3 class="accordion-header"><button class="accordion-button bg-transparent shadow-none fw-semibold" type="button" data-bs-toggle="collapse" data-bs-target="#flSize" aria-expanded="true" aria-controls="flSize">Size</button></h3>
          <div id="flSize" class="accordion-collapse collapse show"><div class="accordion-body pt-0 d-flex flex-wrap gap-2">
            <input type="checkbox" class="btn-check" id="szXS" name="size"><label class="btn btn-outline-secondary rounded-pill px-3" for="szXS">XS</label>
            <input type="checkbox" class="btn-check" id="szS" name="size"><label class="btn btn-outline-secondary rounded-pill px-3" for="szS">S</label>
            <input type="checkbox" class="btn-check" id="szM" name="size" checked><label class="btn btn-outline-secondary rounded-pill px-3" for="szM">M</label>
            <input type="checkbox" class="btn-check" id="szL" name="size"><label class="btn btn-outline-secondary rounded-pill px-3" for="szL">L</label>
            <input type="checkbox" class="btn-check" id="szXL" name="size"><label class="btn btn-outline-secondary rounded-pill px-3" for="szXL">XL</label>
          </div></div>
        </div>
        <div class="accordion-item bg-transparent border-bottom-0">
          <h3 class="accordion-header"><button class="accordion-button collapsed bg-transparent shadow-none fw-semibold" type="button" data-bs-toggle="collapse" data-bs-target="#flRate" aria-expanded="false" aria-controls="flRate">Rating</button></h3>
          <div id="flRate" class="accordion-collapse collapse"><div class="accordion-body pt-0 d-grid gap-2">
            <div class="form-check ps-0 d-flex align-items-center gap-2"><input class="form-check-input ms-0 mt-0" type="radio" name="rate" id="rt4"><label class="form-check-label d-flex align-items-center gap-2" for="rt4"><span class="text-warning d-inline-flex" aria-hidden="true"><svg width="16" height="16" aria-hidden="true"><use href="#flStarF"/></svg><svg width="16" height="16" aria-hidden="true"><use href="#flStarF"/></svg><svg width="16" height="16" aria-hidden="true"><use href="#flStarF"/></svg><svg width="16" height="16" aria-hidden="true"><use href="#flStarF"/></svg><svg width="16" height="16" aria-hidden="true"><use href="#flStarE"/></svg></span><span>4.0 & up</span></label></div>
            <div class="form-check ps-0 d-flex align-items-center gap-2"><input class="form-check-input ms-0 mt-0" type="radio" name="rate" id="rt3"><label class="form-check-label d-flex align-items-center gap-2" for="rt3"><span class="text-warning d-inline-flex" aria-hidden="true"><svg width="16" height="16" aria-hidden="true"><use href="#flStarF"/></svg><svg width="16" height="16" aria-hidden="true"><use href="#flStarF"/></svg><svg width="16" height="16" aria-hidden="true"><use href="#flStarF"/></svg><svg width="16" height="16" aria-hidden="true"><use href="#flStarE"/></svg><svg width="16" height="16" aria-hidden="true"><use href="#flStarE"/></svg></span><span>3.0 & up</span></label></div>
            <div class="form-check ps-0 d-flex align-items-center gap-2"><input class="form-check-input ms-0 mt-0" type="radio" name="rate" id="rt2"><label class="form-check-label d-flex align-items-center gap-2" for="rt2"><span class="text-warning d-inline-flex" aria-hidden="true"><svg width="16" height="16" aria-hidden="true"><use href="#flStarF"/></svg><svg width="16" height="16" aria-hidden="true"><use href="#flStarF"/></svg><svg width="16" height="16" aria-hidden="true"><use href="#flStarE"/></svg><svg width="16" height="16" aria-hidden="true"><use href="#flStarE"/></svg><svg width="16" height="16" aria-hidden="true"><use href="#flStarE"/></svg></span><span>2.0 & up</span></label></div>
          </div></div>
        </div>
      </div>
      <button type="button" class="btn btn-primary rounded-pill w-100 mt-3" id="flApply"><span>Show <span id="flResults">584</span> results</span></button>
      <p class="small text-center wdw-muted mt-2 mb-0" id="flStatus" role="status" aria-live="polite"></p>
    </aside>
  </div>
</section>

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