Skip to main content
Signature

Import

See this widget in action

Preview this widget and its behavior.

About this widget

The searchBox widget is used to let users perform a text-based . This usually is the main entry point to start the search in an InstantSearch context. It’s usually placed at the top of a search experience, so that users can start searching right away.

Examples

JavaScript

Options

string | HTMLElement
required
The CSS Selector or HTMLElement to insert the widget into.
string
The placeholder text of the input.
JavaScript
boolean
default:false
Whether the input should be autofocused.
JavaScript
boolean
default:false
since: v4.64.2
Whether to update the search state in the middle of a composition session. This is useful when users need to search using non-latin characters.
JavaScript
boolean
default:true
If false, triggers the search only on submit.
JavaScript
boolean
default:true
Whether to show the reset button.
JavaScript
boolean
default:true
Whether to show the submit button.
JavaScript
boolean
default:true
Whether to show the loading indicator (replaces the submit button if the search is stalled).
JavaScript
boolean
default:false
Whether to show an AI Mode button in the search box. When users click this button, it opens the Chat widget and sends the current query.To use this option, add a chat() widget on the same index. For an end-to-end walkthrough, see Build an AI-powered search experience.
JavaScript
function
A function that is called just before the search is triggered. It takes two parameters:
  • query: string: the current query string
  • search: function: a function to trigger the search.
If the search method is not called, no search is made to Algolia and the UI doesn’t refresh. If the search method is called, the widget is rendered.This can be useful if you need to:
  • Debounce the number of searches done from the searchBox. You can find more information in the guide on slow network.
  • Programmatically alter the query.
JavaScript
object
The templates to use for the widget.
JavaScript
object
The CSS classes you can override:
  • root: the root element of the widget.
  • form: the form element.
  • input: the input element.
  • reset: the reset button element.
  • resetIcon: the reset button icon.
  • loadingIndicator: the loading indicator element.
  • loadingIcon: the loading indicator icon.
  • submit: the submit button element.
  • submitIcon: the submit button icon.
  • aiModeButton: the AI mode button.
  • aiModeIcon: the AI mode icon.
  • aiModeLabel: the AI mode label.
JavaScript

Templates

You can customize parts of a widget’s UI using the Templates API. Each template includes an html function, which you can use as a tagged template. This function safely renders templates as HTML strings and works directly in the browser—no build step required. For details, see Templating your UI.
The html function is available in InstantSearch.js version 4.46.0 or later.
string | function
The template used for displaying the submit button.
string | function
The template used for displaying the reset button.
string | function
The template used for displaying the loading indicator.
string | function
The template used for displaying the AI Mode button.

HTML output

HTML

Customize the UI with connectSearchBox

If you want to create your own UI of the searchBox widget, you can use connectors. To use connectSearchBox, you can import it with the declaration relevant to how you installed InstantSearch.js.
Then it’s a 3-step process:
JavaScript

Create a render function

This rendering function is called before the first search (init lifecycle step) and each time results come back from Algolia (render lifecycle step).
JavaScript

Render options

string
The query from the current search.
JavaScript
function
Sets a new query and triggers a new search.
JavaScript
function
Removes the query and triggers a new search.
JavaScript
boolean
Returns true if the search results take more than a certain time to come back from Algolia servers. This can be configured on the instantsearch constructor with the attribute stalledSearchDelay.
JavaScript
object
All original widget options forwarded to the render function.
JavaScript

Create and instantiate the custom widget

First, create your custom widgets using a rendering function. Then, instantiate them with parameters. There are two kinds of parameters you can pass:
  • Instance parameters. Predefined options that configure Algolia’s behavior.
  • Custom parameters. Parameters you define to make the widget reusable and adaptable.
Inside the renderFunction, both instance and custom parameters are accessible through connector.widgetParams.
JavaScript

Instance options

function
A function that is called just before the search is triggered. It takes two parameters
  • query: string: the current query string
  • search: function: a function to trigger the search.
If the search method is not called, no search is made to Algolia and the UI doesn’t refresh. If the search method is called, the widget is rendered.This can be useful if you need to:
  • debounce the number of searches done from the searchBox. You can find more information in the guide on slow network.
  • programmatically alter the query.
JavaScript

Full example

Last modified on July 22, 2026