Skip to content

Search with Recent Searches Panel

Search box that opens a panel with recent and trending searches on focus, with keyboard navigation, remove buttons and Clear all.

Also known as: search with suggestions, recent searches dropdown, trending searches panel, search box history, search autocomplete panel

Search with Recent Searches Panel live demo

Open in new tab

Pure CSS code (HTML, CSS, JS)

A search box that opens a panel with recent and trending searches as soon as it gets focus. It is built with plain CSS and vanilla JavaScript and works well for help centers, documentation sites, stores and dashboards where people often repeat the same queries.

How it works

The root .rs-search wraps a form with role="search". The .rs-input is an ARIA combobox: aria-expanded tells assistive technology whether the .rs-panel is open, and aria-controls points to the .rs-listbox. Inside the listbox there are two groups: .rs-group--recent, rendered from an array by the script, and .rs-group--trending, a static list with numbered .rs-rank badges.

The script opens the panel on focus and click, and filters both groups on every input event. Arrow keys move a virtual highlight, the .is-active class, while focus stays in the field; aria-activedescendant points to the highlighted option. Enter on an option runs the search, Delete removes a highlighted recent search, and Escape closes the panel. Clicking the .rs-remove cross removes one entry, .rs-clear empties the list, and .rs-nomatch appears when nothing matches.

A search is saved to the top of the recent list, duplicates are removed, and the list is cut to data-rs-max items. The list is stored in localStorage when it is available. Every storage call is wrapped in try/catch, so sandboxed iframes and private windows fall back to the items written in the markup. The search itself is simulated: replace runSearch() with a fetch() call or a redirect to your results page.

Customization

  • data-rs-max on .rs-search: how many recent searches are kept, 5 by default.
  • data-rs-storage-key: the localStorage key. Use a different key per search box so their histories stay separate.
  • Remove data-rs-open-on-load so the panel opens only when the field is focused. It is set here so the preview shows the panel.
  • --rs-accent in style.css: the orange used for the focus shadow, rank badges, Clear all and the active option bar.
  • --rs-width: the maximum width of the search box and panel.
  • Edit the li items in .rs-group--trending to change trending searches; keep data-value in sync with the text.

Use cases

  • Ecommerce headers: focusing the search box opens recent and trending searches
  • Documentation sites: arrow-key navigation moves through suggestions without the mouse
  • Content apps: remove buttons and Clear all let users manage their search history
  • Marketplaces: trending terms help visitors who are not sure what to type

Accessibility

The input uses role="combobox" with aria-autocomplete="list", options use role="option" with aria-selected, and each group is labelled with aria-labelledby. A visually hidden .rs-hint linked through aria-describedby explains the arrow keys and the Delete shortcut. The .rs-status live region announces searches and removals. Buttons have visible focus outlines, and the drop-in animation is disabled with prefers-reduced-motion.

Usage notes

Several search boxes can share a page: give each input and listbox unique ids, and the script scopes everything to its own .rs-search.

Search with Recent Searches Panel at a glance

Framework
Pure CSS
Code
HTML, CSS, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
None
Layout
Responsive, works on mobile
Category
Search Bars
License
Free for personal and commercial use

Questions about this template

Can I use the Search with Recent Searches Panel code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

There is nothing to install. Paste the HTML where the component should appear, add the CSS to your stylesheet and load the JavaScript before the closing </body> tag. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. The script is plain vanilla JavaScript, so it works without jQuery, React or Vue. You can still use the markup inside those frameworks.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

Requirements

No dependencies. Pure HTML, CSS and JavaScript.

Search with Recent Searches Panel – free Pure CSS search bar template
Search with Recent Searches Panel · free Pure CSS search bar template

More Search Bars

Expanding Search Bar – free Pure CSS search bar template

Expanding Search Bar

Search icon button that expands into a pill-shaped input, shown in a dark navbar and a large hero search, with Escape to close and a demo submit.

Search Bar with Category Dropdown – free Tailwind CSS search bar template

Search Bar with Category Dropdown

Tailwind CSS search bar with an accessible category dropdown on the left, popular search chips and a simulated result count.

Search with Autocomplete – free Bootstrap 5 search bar template

Search with Autocomplete

Bootstrap 5 help center search bar with an accessible autocomplete list built from local data, highlighted matches, keyboard navigation and popular search chips.

Command Palette Search – free Tailwind CSS search bar template

Command Palette Search

Dark Tailwind CSS command palette opened with Ctrl+K: live filtering with match highlights, grouped results and full keyboard navigation.