About this set
Three search bars built into a site header, where search has to share a row with a logo, navigation and account controls. The first is a field that widens from 190 to 300 pixels while it has focus, giving the query room without taking space from the menu the rest of the time. The second starts as a round, icon-sized field and opens into a full input on focus, with the shop name stepping aside on phones so the field has room. The third is an app bar with a centred search, a slash key hint and an account button; pressing the slash key anywhere on the page jumps to the field. The widening is plain CSS: the input width transitions on :focus, and the icon field stays open while it holds text through :not(:placeholder-shown). Only the slash shortcut uses JavaScript, a single keydown listener that ignores the key while someone is typing in another field. Use the widening field on content sites, the icon field in e-commerce headers and the app bar in dashboards.
What’s included
- Field that widens on focus with a CSS width transition
- Icon field that opens into a full input, no JavaScript
- App bar search with a slash shortcut and aria-keyshortcuts
- Navigation links hide on small screens so the header never overflows
- Bootstrap version built on .navbar and .navbar-nav
Accessibility
Each search form has role="search" and its own aria-label, the inputs have visually hidden labels, and the collapsed icon field is still a normal text input that screen readers announce by its label. The slash hint is aria-hidden and the input carries aria-keyshortcuts="/". Links and buttons show a 2px outline on :focus-visible, fields show an accent ring, and the width animation is switched off under prefers-reduced-motion.
Customise it
Set --hs-accent, --hs-line and --hs-ring on .hs for colour; change the width values on .hs-grow and .hs-icon inputs to adjust how far they open. Bootstrap uses the same properties plus --bs-navbar-* variables; in Tailwind edit the --color-hs-* theme colours and the w-[190px], focus:w-[300px] and w-[42px] utilities.






