Signature
See this widget in action
Preview this widget and its behavior.
About this widget
Thepagination widget displays a pagination system which lets users change the current page of search results.
Pagination is limited to 1,000 hits per page.
For more information, see Pagination limitations.
Examples
JavaScript
Options
string | HTMLElement
required
The CSS Selector or
HTMLElement to insert the widget into.boolean
default:true
Whether to display the first page link.
JavaScript
boolean
default:true
Whether to display the previous page link.
JavaScript
boolean
default:true
Whether to display the next page link.
JavaScript
boolean
default:true
Whether to display the last page link.
JavaScript
number
default:3
The number of pages to display on each side of the current page.
JavaScript
number
The maximum number of pages to browse.
JavaScript
string | HTMLElement | boolean
default:"body"
Where to scroll after a click. Set to
false to disable.object
default:"{}"
The CSS classes you can override:
root. The root element of the widget.noRefinementRoot. The root container without results.list. The list of results.item. The item in the list of results.firstPageItem. The first item.lastPageItem. The last item.previousPageItem. The previous item.nextPageItem. The next item.pageItem. The page items.selectedItem. The selected item.disabledItem. The disabled item.link. The link elements.
JavaScript
Templates
You can customize parts of a widget’s UI using the Templates API. Each template includes anhtml 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 for the first page.
string | function
The template for the previous page.
string | function
The template for the next page.
string | function
The template for the last page.
HTML output
HTML
Customize the UI with connectPagination
If you want to create your own UI of the pagination widget, you can use connectors.
To use connectPagination, you can import it with the declaration relevant to how you installed InstantSearch.js.
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
If SEO is important for your search page, ensure that your custom HTML is optimized for search engines:
- Use
<a>tags withhrefattributes to allow search engine bots to follow links. - Use semantic HTML and include structured data when relevant.
Rendering options
number[]
The pages relevant to the current situation and padding.
JavaScript
number
The number of the page currently displayed.
JavaScript
number
The number of hits computed for the last query (can be approximate).
JavaScript
number
The number of pages for the result set.
JavaScript
boolean
Whether the current page is the first page.
JavaScript
boolean
Whether the current page is the last page.
JavaScript
boolean
required
Indicates if search state can be refined.
JavaScript
function
Sets the current page and triggers a search.
JavaScript
function
Generates a URL for the next state.
The number is the page to generate the URL for.
JavaScript
function
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.
renderFunction, both instance and custom parameters are accessible through connector.widgetParams.
JavaScript
Instance options
number
The total number of pages to browse.
JavaScript
number
default:3
The padding of pages to show around the current page
JavaScript