Snippets Forms

Bootstrap 5 Ecommerce Search Form with Suggestions

A pill-shaped ecommerce search bar with live suggestions and quick-pick category chips.

Bootstrap 5 No jQuery May 2019 3.7K views

<section class="wdw-stage">
  <div class="container" style="max-width: 720px">
    <div class="text-center mb-4">
      <span class="wdw-eyebrow">Shop the season</span>
      <h1 class="wdw-heading display-6 mt-2 mb-2">What are you looking for?</h1>
      <p class="wdw-muted mb-0">Search 12,000+ pieces across fashion, accessories and home.</p>
    </div>

    <form class="wdw-card p-3 p-md-4 position-relative" role="search" id="shopSearch" autocomplete="off">
      <label for="shopSearchInput" class="visually-hidden">Search the store</label>
      <div class="shop-search d-flex align-items-center gap-2 rounded-pill px-3">
        <svg class="flex-shrink-0 text-body-secondary" width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5"/></svg>
        <input id="shopSearchInput" class="shop-search-input flex-grow-1 border-0 bg-transparent" type="search" placeholder="Search the store…" role="combobox" aria-expanded="true" aria-controls="shopSuggest" aria-autocomplete="list" aria-activedescendant="">
        <button class="btn btn-primary rounded-pill px-4" type="submit">Search</button>
      </div>

      <div id="shopPanel" class="shop-panel mt-3">
        <div id="shopHead" class="d-flex justify-content-between align-items-center px-1 mb-2"><span class="wdw-eyebrow">Trending now</span><span class="small wdw-muted">Use ↑ ↓ to browse</span></div>
        <ul id="shopSuggest" class="list-unstyled shop-suggest m-0" role="listbox" aria-label="Suggested products">
        <li class="shop-opt" role="option" id="shopOpt0" aria-selected="false" data-v="Linen summer dress">
          <span class="shop-thumb flex-shrink-0 d-inline-flex align-items-center justify-content-center rounded-3 bg-body-secondary text-body-secondary"><svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9 3h6l1 6-2 12h-4L8 9l1-6Z"/></svg></span>
          <span class="flex-grow-1 min-w-0"><span class="d-block fw-semibold text-body-emphasis shop-name">Linen summer dress</span><span class="d-block small wdw-muted">Ladies</span></span>
          <span class="fw-bold text-body-emphasis">$64</span>
        </li>
        <li class="shop-opt" role="option" id="shopOpt1" aria-selected="false" data-v="Leather court sneakers">
          <span class="shop-thumb flex-shrink-0 d-inline-flex align-items-center justify-content-center rounded-3 bg-body-secondary text-body-secondary"><svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 17v-3l5-2 3 2h4a6 6 0 0 1 6 3v0H3Z"/><path d="M3 17v2h18v-2"/></svg></span>
          <span class="flex-grow-1 min-w-0"><span class="d-block fw-semibold text-body-emphasis shop-name">Leather court sneakers</span><span class="d-block small wdw-muted">Mens</span></span>
          <span class="fw-bold text-body-emphasis">$98</span>
        </li>
        <li class="shop-opt" role="option" id="shopOpt2" aria-selected="false" data-v="Weekender tote bag">
          <span class="shop-thumb flex-shrink-0 d-inline-flex align-items-center justify-content-center rounded-3 bg-body-secondary text-body-secondary"><svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 8h14l1 13H4L5 8Z"/><path d="M9 8V6a3 3 0 0 1 6 0v2"/></svg></span>
          <span class="flex-grow-1 min-w-0"><span class="d-block fw-semibold text-body-emphasis shop-name">Weekender tote bag</span><span class="d-block small wdw-muted">Accessories</span></span>
          <span class="fw-bold text-body-emphasis">$82</span>
        </li>
        <li class="shop-opt" role="option" id="shopOpt3" aria-selected="false" data-v="Classic steel watch">
          <span class="shop-thumb flex-shrink-0 d-inline-flex align-items-center justify-content-center rounded-3 bg-body-secondary text-body-secondary"><svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="5"/><path d="M9 7l.5-4h5L15 7M9 17l.5 4h5l.5-4M12 10v2l1.5 1"/></svg></span>
          <span class="flex-grow-1 min-w-0"><span class="d-block fw-semibold text-body-emphasis shop-name">Classic steel watch</span><span class="d-block small wdw-muted">Accessories</span></span>
          <span class="fw-bold text-body-emphasis">$129</span>
        </li>
        </ul>
        <p id="shopEmpty" class="small wdw-muted text-center my-3" hidden>No matches. Try “dress” or “watch”.</p>
      </div>

      <div class="d-flex flex-wrap align-items-center gap-2 mt-3 px-1">
        <span class="small wdw-muted me-1">Popular:</span>
        <button type="button" class="btn btn-sm rounded-pill bg-body-tertiary border-0 text-body shop-chip" data-term="New arrivals">New arrivals</button>
        <button type="button" class="btn btn-sm rounded-pill bg-body-tertiary border-0 text-body shop-chip" data-term="Ladies">Ladies</button>
        <button type="button" class="btn btn-sm rounded-pill bg-body-tertiary border-0 text-body shop-chip" data-term="Mens">Mens</button>
        <button type="button" class="btn btn-sm rounded-pill bg-body-tertiary border-0 text-body shop-chip" data-term="Accessories">Accessories</button>
        <button type="button" class="btn btn-sm rounded-pill bg-body-tertiary border-0 text-danger-emphasis shop-chip" data-term="Sale">Sale</button>
      </div>
    </form>
    <p id="shopSearchResult" class="text-center small wdw-muted mt-3 mb-0" aria-live="polite"></p>
  </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.