Skip to main content
Signature

Import

See this widget in action

Preview this widget and its behavior.

About this widget

The stats widget displays the total number of matching hits and the time it took to get them (time spent in the Algolia server).

Examples

JavaScript

Options

container
string | HTMLElement
required
The CSS Selector or HTMLElement to insert the widget into.
templates
object
The templates to use for the widget.
JavaScript
cssClasses
object
default:"{}"
The CSS classes you can override:
  • root. The root element of the widget.
  • text. The text element.
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.
text
string | function
The template to use to customize the text. It exposes:
  • hitsPerPage: number. The maximum number of hits returned per page.
  • nbPages: number. The number of pages returned. Calculation is based on the total number of hits (nbHits) divided by the number of hits per page (hitsPerPage), rounded up to the nearest integer.
  • nbHits: number. The number of hits matched by the .
  • areHitsSorted: boolean. True if the index is currently using relevant sort and displaying only sorted hits.
  • nbSortedHits: number. The number of sorted hits matched by the query (when using relevant sort).
  • page: number. The index of the current page (zero-based).
  • processingTimeMS: number. The time the server took to process the , in milliseconds. This doesn’t include network time.
  • query: string. The query text.
  • hasManyResults: boolean. Indicates whether the search has more than one result.
  • hasNoResults: boolean. Indicates whether the search has no results.
  • hasOneResult: boolean. Indicates whether the search has one result.
  • areHitsSorted: boolean. Indicates whether Relevant sort is applied to the result.
  • nbSortedHits: number. The number of sorted hits from Relevant sort.
  • hasManySortedResults: boolean. Indicates whether the search has more than one sorted result.
  • hasNoSortedResults: boolean. Indicates whether the search has no sorted results.
  • hasOneSortedResults: boolean. Indicates whether the search has one sorted result.
  • cssClasses: object. Same option as the cssClasses parameter provided to the widget.

HTML output

HTML

Customize the UI with connectStats

If you want to create your own UI of the stats widget, you can use connectors. To use connectStats, 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

Rendering options

hitsPerPage
number
The maximum number of hits returned per page.
JavaScript
nbHits
number
The number of hits matched by the query.
JavaScript
areHitsSorted
boolean
Indicates whether relevant sort is applied to the result.
JavaScript
nbSortedHits
number
The number of sorted hits from relevant sort.
JavaScript
nbPages
number
The number of returned pages. The calculation is based on the total number of hits (nbHits) divided by the number of hits per page (hitsPerPage), rounded up to the nearest integer.
JavaScript
page
number
The position of the current page (zero-based).
JavaScript
processingTimeMS
number
The time the server took to process the request, in milliseconds. This doesn’t include network time.
JavaScript
query
string
The query sent to the server.
JavaScript
widgetParams
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

Full example

Last modified on July 10, 2026