Snippets Forms

Bootstrap 5 Search Form with Category Dropdown

A pill-shaped store search bar with a category dropdown, keyword field and search button, plus one-tap popular searches underneath.

Bootstrap 5 No jQuery May 2019 3.3K views

<section class="wdw-stage py-4">
  <div class="container" style="max-width:940px">
    <div class="text-center mb-5">
      <span class="wdw-eyebrow">Shop search</span>
      <h1 class="wdw-heading display-3 mt-1 mb-3">Find anything in the store</h1>
      <p class="wdw-muted mb-0">Pick a category, type a keyword, or jump straight to a popular search.</p>
    </div>

    <form class="wdw-card p-3" id="shopSearch" role="search" onsubmit="return false">
      <div class="d-flex flex-column flex-md-row align-items-stretch gap-2">
        <div class="dropdown">
          <button class="btn border-0 bg-body-tertiary text-body-emphasis rounded-pill px-4 w-100 justify-content-between" type="button" id="catBtn" data-bs-toggle="dropdown" aria-expanded="false" style="min-width:190px;min-height:60px">
            <span class="d-inline-flex align-items-center gap-2">
              <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="3" y="3" width="7.5" height="7.5" rx="2"/><rect x="13.5" y="3" width="7.5" height="7.5" rx="2"/><rect x="3" y="13.5" width="7.5" height="7.5" rx="2"/><rect x="13.5" y="13.5" width="7.5" height="7.5" rx="2"/></svg>
              <span id="catLabel">All categories</span>
            </span>
            <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m6 9 6 6 6-6"/></svg>
          </button>
          <ul class="dropdown-menu p-2 w-100" aria-labelledby="catBtn">
            <li><button type="button" class="dropdown-item rounded-3 active" aria-current="true">All categories</button></li>
            <li><button type="button" class="dropdown-item rounded-3">New arrivals</button></li>
            <li><button type="button" class="dropdown-item rounded-3">Sale</button></li>
            <li><button type="button" class="dropdown-item rounded-3">Ladies</button></li>
            <li><button type="button" class="dropdown-item rounded-3">Men</button></li>
            <li><button type="button" class="dropdown-item rounded-3">Footwear</button></li>
            <li><button type="button" class="dropdown-item rounded-3">Accessories</button></li>
          </ul>
        </div>

        <div class="position-relative flex-grow-1">
          <label for="shopQuery" class="visually-hidden">Search keywords</label>
          <svg class="position-absolute top-50 translate-middle-y wdw-muted" style="left:1.1rem" width="18" height="18" 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="shopQuery" type="search" class="form-control border-0 bg-transparent h-100 ps-5 shadow-none" style="min-height:60px" placeholder="Search for linen shirts, sneakers…" autocomplete="off">
        </div>

        <button type="submit" class="btn btn-primary rounded-pill px-4" style="min-height:60px">Search</button>
      </div>
    </form>

    <div class="d-flex flex-wrap justify-content-center align-items-center gap-2 mt-5" id="chips">
      <span class="small wdw-muted me-1">Popular</span>
      <button type="button" class="btn btn-sm btn-outline-secondary rounded-pill px-3">Linen shirts</button>
      <button type="button" class="btn btn-sm btn-outline-secondary rounded-pill px-3">White sneakers</button>
      <button type="button" class="btn btn-sm btn-outline-secondary rounded-pill px-3">Summer dresses</button>
      <button type="button" class="btn btn-sm btn-outline-secondary rounded-pill px-3">Leather belts</button>
    </div>
    <p class="text-center small wdw-muted mt-3 mb-0" id="searchStatus" role="status" aria-live="polite">Showing 1,248 products across all categories</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.