Skip to main content
Signature

Import

See this widget in action

Preview this widget and its behavior.

About this widget

The hitsPerPage widget displays a menu for letting users change the number of displayed hits. If you only want to configure the number of hits per page without displaying a widget, you can use the configure widget with the hitsPerPage search parameter.

Examples

JavaScript

Options

container
string | HTMLElement
required
The CSS Selector or HTMLElement to insert the widget into.
items
object[]
required
The list of available options, with each item:
  • label: string. The label to display in the option.
  • value: number. The number of hits to display per page.
  • default: boolean. The default hits per page on first search.
JavaScript
cssClasses
object
default:"{}"
The CSS classes you can override:
  • root. The root element of the widget.
  • select. The select element.
  • option. The option elements of the select.
JavaScript
transformItems
function
default:"items => items"
A function that receives the list of items before they are displayed. It should return a new array with the same structure. Use this to transform, filter, or reorder the items.The function also has access to the full results data, including all standard response parameters and parameters from the helper, such as disjunctiveFacetsRefinements.
JavaScript

HTML output

HTML

Customize the UI with connectHitsPerPage

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

items
object[]
The list of items the widget can display, with each item:
  • label: string. The label to display in the option.
  • value: number. The number of hits to display per page.
  • isRefined: boolean. Indicates if the item is the current refined value.
JavaScript
canRefine
boolean
since: v4.45.0
Whether the search can be refined.
JavaScript
refine
function
Sets the number of hits per page and triggers a search.
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

Instance options

items
object[]
required
The list of available options, with each item:
  • label: string. The label to display in the option.
  • value: number. The number of hits to display per page.
  • default: boolean. The default hits per page on first search.
JavaScript
transformItems
function
default:"items => items"
A function that receives the list of items before they are displayed. It should return a new array with the same structure. Use this to transform, filter, or reorder the items.The function also has access to the full results data, including all standard response parameters and parameters from the helper, such as disjunctiveFacetsRefinements.
JavaScript

Full example

Last modified on July 10, 2026