Skip to main content
Autocomplete is also available as an experimental widget in InstantSearch, making it easier to integrate into your search experience. For more information, see the API reference for InstantSearch.js or React InstantSearch.
When you think of search experiences on sites like Amazon (ecommerce) or YouTube (media), you may notice that both sites use an autocomplete experience. It’s the autocomplete, and not just a search input, that powers the search page. If you have an existing InstantSearch implementation, you can create a similar experience by adding Autocomplete to your InstantSearch application. Adding Autocomplete to an existing InstantSearch implementation lets you enhance the search experience and create a richer, more contextual search. You can use context from the current user and how they interacted with your site, save their recent searches, provide suggested queries, and more. This autocomplete can work as a rich search box in a search page, and a portable all-in-one search experience anywhere else on your site. This guide shows you how to integrate Autocomplete with InstantSearch on your site. Screenshot of a search interface with 'air' entered, showing autocomplete suggestions and product results for Apple devices.

Open CodeSandbox

Run and edit the Autocomplete with InstantSearch.js example in CodeSandbox.

Explore source code

Browse the source for the Autocomplete with InstantSearch.js example on GitHub.
This guide starts from a brand new InstantSearch application, but you can adapt it to integrate Autocomplete in your existing implementation.

Create a search page with InstantSearch

First, begin with some starter code. In a new project, create an index.html file and add the following code:
HTML
The search page uses a two-column layout with categories on the left, and a search box, hits, and a pagination widget on the right. Next, create the app.js file to instantiate InstantSearch.
JavaScript
This InstantSearch implementation imports the default historyRouter router which you want to reuse in your Autocomplete integration. This lets InstantSearch understand query parameters from the URL to derive its state. If your Algolia doesn’t have hierarchical attributes, you can use a regular attribute with a menu widget. You should now have a working InstantSearch application. InstantSearch ships with a searchBox component, but it doesn’t provide autocomplete features like you see on YouTube and Amazon. Instead, you can replace the searchBox with an autocomplete experience, using Autocomplete. Start by removing the InstantSearch #searchbox container and adding the Autocomplete container, named #autocomplete here.
HTML
You want the Autocomplete experience to be available on all the pages of the site, not only the search page, so you can move its container to a header or navigation bar instead of the page content. Next, you can virtualize the searchBox from your InstantSearch implementation and instantiate Autocomplete in your app.js file.
JavaScript
This replaces the InstantSearch search box with Autocomplete, and acts exactly like before. But you can now add many more interesting features.

Add recent searches

When you make a search on YouTube or Google and come back to the search box later on, the autocomplete displays your recent searches. This pattern lets users quickly access content by using the same path they took to find it in the first place. Autocomplete lets you add recent searches with the @algolia/autocomplete-plugin-recent-searches package. It exposes a createLocalStorageRecentSearchesPlugin function to let you create a recent searches plugin.
Some of this code is abstracted away in the following sections to simplify the examples. Since the recentSearchesPlugin reads from localStorage, you can’t see any recent searches until you perform at least one query. To submit a search, make sure to press Enter on the query. Once you do, you’ll see it appear as a recent search. See also:

Add Query Suggestions

The most typical pattern you can see on every autocomplete is suggestions. They’re predictions of queries that match what users are currently typing, and that guarantee to return results. For example, when typing “how to” in Google, the search engine suggests matching suggestions for users to complete their query. It’s especially useful on mobile, where typing is harder than on a physical keyboard. Autocomplete lets you add Query Suggestions with the @algolia/autocomplete-plugin-query-suggestions package. It exposes a createQuerySuggestionsPlugin function to let you create a Query Suggestions plugin. This plugin requires a Query Suggestions index.
See also:

Debounce search results

Having two sets of results update as you type generates many UI flashes. This is distracting for users, because two distinct sections of the page are competing for their attention. You can mitigate this problem by debouncing search results.
JavaScript

Support categories in Query Suggestions

A key feature to Autocomplete is to pre-configure your InstantSearch page. The Query Suggestions plugin supports categories that you can use to refine both the query and the category in a single interaction This pattern brings users to the right category without interacting with the hierarchicalMenu widget, only with the autocomplete.
1

Add category support to the helpers

You need to support categories in the helpers you created at the beginning:
2

Send category to the helpers

Update the plugins to forward the category to the helpers:
3

Reset the InstantSearch category

Implement the onReset function on your Autocomplete instance to also reset the InstantSearch category.
JavaScript

Add contextual Query Suggestions

For an even richer Autocomplete experience, you can pick up the currently active InstantSearch category and provide suggestions for both this specific category and others. This pattern lets you reduce the scope of the search to the current category, like an actual department store, or broaden the suggestions to get out of the current category. Query Suggestions with current InstantSearch category First, make sure to set your category attribute as a facet in your Query Suggestions index. In this demo, the attribute to facet is instant_search.facets.exact_matches.hierarchicalCategories.lvl0.value.

Next steps

Autocomplete is now the main user interaction point driving InstantSearch to refine search results. From now on, you’re leveraging the complete Autocomplete ecosystem to bring a state-of-the-art search experience for desktop and mobile. You can now add Autocomplete everywhere on your site and redirect users to the search page whenever they submit a search, or after they select a suggestion. You can also use context from the current page to personalize the autocomplete experience. For example, you could display a preview of matching results in a panel for each suggestion, and let InstantSearch provide these results once on the search page. Code examples:
Last modified on July 14, 2026