Hidden search

Zero JavaScript: the native details toggle drives the animation via ::details-content.

.hidden-search is a details element whose summary is a round button with a magnifier. On open, the form unfolds from the right with a scaleX transition on ::details-content (allow-discrete, so it animates on close too), the magnifier swaps for a close icon, and the pill-shaped search input takes the elevation. On screens below lg the field spans 80vw instead of 30vw.

Zero JavaScript: the native details toggle drives everything, keyboard and focus behavior included, and the icon swap is pure CSS on [open]. Perfect for header bars where the search should stay out of the way.

Give the summary the classes btn and btn-round so it matches the pill-shaped search field. The search icon follows the $icon-search placeholder, the field radius is 50px, widths are 30vw (80vw below lg) and the transition uses $transition-fast with allow-discrete.

Hidden search

Try it: the toggle is the native details behavior, so keyboard, focus and screen readers work with zero JavaScript; the icon swap is pure CSS on [open].

HTML
<details class="hidden-search">
  <summary class="btn btn-round" aria-label="Open search">
    <i class="search-icon"><svg class="bi" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true"><circle cx="7" cy="7" r="4.5"/><path d="M10.5 10.5 14 14"/></svg></i>
    <i class="close-icon"><svg class="bi" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true"><path d="M4 4l8 8M12 4l-8 8"/></svg></i>
  </summary>
  <form>
    <input type="search" placeholder="Search the docs">
  </form>
</details>