Snippets Search

Bootstrap 5 Search Input with Icon (3 Styles)

Three search box patterns: a rounded input with an icon and keyboard shortcut hint, an input group with a search button, and a filled field with a clear button. Pressing the slash key focuses the first.

Bootstrap 5 No jQuery Jul 2019 17.4K views

<section class="wdw-stage sr-stage">
  <div class="container" style="max-width: 1000px;">
    <div class="text-center mb-5">
      <span class="wdw-eyebrow mb-3">Search</span>
      <h1 class="h2 wdw-heading mb-2">Search inputs</h1>
      <p class="text-body-secondary mb-0">Three search boxes and a command palette. Press <kbd>/</kbd> for the first, <kbd>Ctrl</kbd> <kbd>K</kbd> or <kbd>⌘K</kbd> for the palette.</p>
    </div>
    <div class="row g-3 g-md-4 align-items-stretch">
      <div class="col-lg-6">
        <div class="card wdw-card h-100"><div class="card-body p-4 d-flex flex-column gap-4"><div><p class="fw-semibold text-body-emphasis mb-0">Search fields</p><p class="small text-body-secondary mb-0">Three patterns for the same job</p></div>
          <form role="search" class="sr-form">
            <label class="form-label small fw-semibold text-body-secondary" for="srA">Icon inside, with shortcut</label>
            <div class="sr-field position-relative">
              <svg class="sr-icon" width="18" height="18" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><circle cx="9" cy="9" r="6"/><path d="m14 14 4 4"/></svg>
              <input id="srA" type="search" class="form-control rounded-pill sr-input" placeholder="Search articles">
              <kbd class="sr-kbd" aria-hidden="true">/</kbd>
            </div>
          </form>
          <form role="search" class="sr-form">
            <label class="form-label small fw-semibold text-body-secondary" for="srB">Separate input and button</label>
            <div class="d-flex gap-2">
              <input id="srB" type="search" class="form-control rounded-pill ps-4 sr-input-plain" placeholder="Search this blog">
              <button class="btn btn-primary rounded-pill px-3 px-sm-4" type="submit">Search</button>
            </div>
          </form>
          <form role="search" class="sr-form">
            <label class="form-label small fw-semibold text-body-secondary" for="srC">Filled with clear button</label>
            <div class="sr-field position-relative">
              <svg class="sr-icon" width="18" height="18" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><circle cx="9" cy="9" r="6"/><path d="m14 14 4 4"/></svg>
              <input id="srC" type="text" class="form-control border-0 bg-body-secondary rounded-pill sr-input" value="Pricing table" placeholder="Find a component" autocomplete="off">
              <button type="button" class="btn-close sr-clear" aria-label="Clear search"></button>
            </div>
          </form>
        </div></div>
      </div>
      <div class="col-lg-6">
        <div class="card wdw-card h-100 overflow-hidden sr-palette">
          <form role="search" class="sr-form position-relative border-bottom">
            <label class="visually-hidden" for="srP">Search the library</label>
            <svg class="sr-icon" width="18" height="18" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><circle cx="9" cy="9" r="6"/><path d="m14 14 4 4"/></svg>
            <input id="srP" type="search" class="form-control form-control-lg border-0 rounded-0 sr-input bg-transparent" role="combobox" aria-expanded="true" aria-autocomplete="list" placeholder="Search components, pages..." autocomplete="off" aria-controls="srList">
            <kbd class="sr-kbd d-none d-sm-inline" aria-hidden="true">Ctrl K</kbd>
          </form>
          <div class="px-3 pt-3">
            <p class="small fw-semibold text-body-secondary mb-2">Recent</p>
            <div class="d-flex flex-wrap gap-2" id="srChips">
              <button type="button" class="btn btn-sm btn-outline-secondary rounded-pill" data-q="navbar">navbar</button>
              <button type="button" class="btn btn-sm btn-outline-secondary rounded-pill" data-q="modal">modal</button>
              <button type="button" class="btn btn-sm btn-outline-secondary rounded-pill" data-q="pricing">pricing</button>
            </div>
          </div>
          <div class="list-group list-group-flush p-2 mt-1" id="srList" role="listbox" aria-label="Results">
            <a href="#" id="srO0" role="option" aria-selected="true" class="list-group-item list-group-item-action rounded-3 border-0 d-flex align-items-center gap-3 sr-active" data-t="navbar responsive"><span class="sr-ico">N</span><span class="flex-grow-1"><span class="d-block fw-medium text-body-emphasis">Responsive navbar</span><span class="small text-body-secondary">Components</span></span></a>
            <a href="#" id="srO1" role="option" aria-selected="false" class="list-group-item list-group-item-action rounded-3 border-0 d-flex align-items-center gap-3" data-t="modal dialog"><span class="sr-ico">M</span><span class="flex-grow-1"><span class="d-block fw-medium text-body-emphasis">Modal dialog</span><span class="small text-body-secondary">Components</span></span></a>
            <a href="#" id="srO2" role="option" aria-selected="false" class="list-group-item list-group-item-action rounded-3 border-0 d-flex align-items-center gap-3" data-t="pricing table plans"><span class="sr-ico">P</span><span class="flex-grow-1"><span class="d-block fw-medium text-body-emphasis">Pricing table</span><span class="small text-body-secondary">Sections</span></span></a>
            <a href="#" id="srO3" role="option" aria-selected="false" class="list-group-item list-group-item-action rounded-3 border-0 d-flex align-items-center gap-3" data-t="login form auth"><span class="sr-ico">L</span><span class="flex-grow-1"><span class="d-block fw-medium text-body-emphasis">Login form</span><span class="small text-body-secondary">Forms</span></span></a>
            <p class="text-center text-body-secondary small py-3 mb-0 d-none" id="srNone">No results found.</p>
          </div>
        </div>
      </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.