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.
By default, it uses Preact 10 to render templates.

Installation

First, you need to install the package.
Then import it in your project:
JavaScript
If you don’t use a package manager, you can use the HTML script element:
HTML

Example

Make sure to define an empty container in your HTML where to inject your autocomplete.
JavaScript
This example uses Autocomplete with an Algolia , along with the algoliasearch API client. All Algolia utility functions to retrieve hits and parse results are available directly in the package.

Parameters

string | HTMLElement
required
The container for the Autocomplete search box. You can either pass a CSS selector or an Element. If there are several containers matching the selector, Autocomplete picks up the first one.
string | HTMLElement
The container for the Autocomplete panel. You can either pass a CSS selector or an Element. If there are several containers matching the selector, Autocomplete picks up the first one.
"start" | "end" | "full-width" | "input-wrapper-width"
default:"input-wrapper-width"
The panel’s horizontal position.
boolean | InsightsPluginOptions
default:false
Whether to enable the Algolia Insights plugin.This option accepts an object to configure the plugin. You can see the available options in the plugin’s documentation.If you don’t pass an insightsClient, it will be automatically detected from the window object, or downloaded from the jsDelivr CDN.If you manually enable the Insights plugin, this option won’t have any effect.
Translations
Type definition
A dictionary of translations to support internationalization.
ClassNames
Class names to inject for each created DOM element. This is useful to style your autocomplete with external CSS frameworks.
Type definition
Components to register in the Autocomplete rendering lifecycles. Registered components become available in templates, render, and in renderNoResults.
Four components are registered by default:
  • Highlight to highlight matches in Algolia results.
  • Snippet to snippet matches in Algolia results.
  • ReverseHighlight to reverse highlight matches in Algolia results.
  • ReverseSnippet to reverse highlight and snippet matches in Algolia results.
function
Type definition
The function that renders the autocomplete panel. This is useful to customize the rendering, for example, using multi-row or multi-column layouts.This is the default implementation:
JavaScript
You can use sections, which holds the components tree of your autocomplete, to customize the wrapping layout.
If you need to split the content across a more complex layout, you can use elements instead to pick which source to display based on its sourceId.
function
Type definition
The function that renders a no results section when there are no hits. This is useful to let users know that the query returned no results.There’s no default implementation. By default, Autocomplete closes the panel when there’s no results. Here’s how you can customize this behavior:
JavaScript
The virtual DOM implementation to plug to Autocomplete. It defaults to Preact.
string
default:"(max-width: 680px)"
The detached mode turns the dropdown display into a full screen, modal experience.For more information, see Detached mode.
The autocomplete function also accepts all the props that createAutocomplete supports:
The sources to get the collections from.
Reshape
The function called to reshape the sources after they’re resolved.This is useful to transform sources before rendering them. You can group sources by attribute, remove duplicates, create shared limits between sources, etc.See Reshaping sources for more information.
TypeScript
boolean | InsightsPluginOptions
default:false
Whether to enable the Algolia Insights plugin.This option accepts an object to configure the plugin. You can see the available options in the plugin’s documentation.If you don’t pass an insightsClient, it will be automatically detected from the window object, or downloaded from the jsDelivr CDN.If you manually enable the Insights plugin, this option won’t have any effect.
string
An ID for the autocomplete to create accessible attributes.
(params: { state: AutocompleteState<TItem> }) => void
The function called when the internal state changes.
"enter" | "done" | "go" | "next" | "previous" | "search" | "send"
since: v1.10.0
The action label or icon to present for the enter key on virtual keyboards.
boolean
default:false
since: v1.15.1
Whether to update the search input value in the middle of a composition session. This is useful when users need to search using non-latin characters.
string
The placeholder text to show in the search input when there’s no query.
boolean
default:false
Whether to focus the search input or not when the page is loaded.
number | null
default: null
The default item index to pre-select.You should use 0 when the autocomplete is used to open links, instead of triggering a search in an application.
boolean
default:false
Whether to open the panel on focus when there’s no query.
number
default:300
How many milliseconds must elapse before considering the autocomplete experience stalled.
Partial<AutocompleteState>
The initial state to apply when autocomplete is created.
typeof window
default: window
The environment in which your application is running.This is useful if you’re using autocomplete in a different context than window.
Navigator
An implementation of Autocomplete’s Navigator API to redirect users when opening a link.Learn more on the Navigator API documentation.
(params: { state: AutocompleteState }) => boolean
The function called to determine whether the panel should open or not.By default, the panel opens when there are items in the state.
(params: { state: AutocompleteState, event: Event, ...setters }) => void
The function called when submitting the Autocomplete form.
(params: { state: AutocompleteState, event: Event, ...setters }) => void
The function called when resetting the Autocomplete form.
boolean
default:false
A flag to activate the debug mode.This is useful while developing because it keeps the panel open even when the blur event occurs. Make sure to turn it off in production.See Debugging for more information.
The plugins that encapsulate and distribute custom Autocomplete behaviors.See Plugins for more information.

Components

Autocomplete exposes components to all templates to share them everywhere in the instance.

Highlight

THit
required
The Algolia hit whose attribute to retrieve the highlighted parts from.
keyof THit | string[]
required
The attribute to retrieve the highlighted parts from.
string
default:"mark"
The tag name to use for highlighted parts.

Snippet

THit
required
The Algolia hit whose attribute to retrieve the snippeted parts from.
keyof THit | string[]
required
The attribute to retrieve the snippeted parts from.
string
default:"mark"
The tag name to use for snippeted parts.

ReverseHighlight

THit
required
The Algolia hit whose attribute to retrieve the reverse highlighted parts from.
keyof THit | string[]
required
The attribute to retrieve the reverse highlighted parts from.
string
default:"mark"
The tag name to use for reverse highlighted parts.

ReverseSnippet

THit
required
The Algolia hit whose attribute to retrieve the reverse snippeted parts from.
keyof THit | string[]
required
The attribute to retrieve the reverse snippeted parts from.
string
default:"mark"
The tag name to use for reverse snippeted parts.

Returns

The autocomplete function returns state setters and a refresh method that updates the UI state with fresh sources. These setters are useful to control the autocomplete experience from external events.
JavaScript
The autocomplete function returns state setters and helpers:
() => Promise<void>
Updates the UI state with fresh sources. You must call this function whenever you mutate the state with setters and want to reflect the changes in the UI.
(updatedOptions: Partial<AutocompleteOptions>) => void
Updates the Autocomplete instance with new options.
() => void
Destroys the Autocomplete instance and removes it from the DOM.
Last modified on June 19, 2026