Pagination
A navigation component that allows users to browse through pages.
Anatomy
<Pagination.Root>
<Pagination.PrevTrigger />
<Pagination.Item />
<Pagination.Ellipsis />
<Pagination.NextTrigger />
</Pagination.Root>
Examples
Controlled
Use page and onPageChange to control the current page.
Root Provider
Use RootProvider with the usePagination hook to access the state and methods from outside the component.
Customization
Customize with props like dir, pageSize, siblingCount and translations.
Context
Pagination.Context and the usePaginationContext hook expose methods like setPage, setPageSize, goToNextPage,
goToPreviousPage, goToFirstPage and goToLastPage, and properties like totalPages and pageRange.
Data Slicing
slice() returns the items of a data array for the current page and page size.
Page Range
Use pageRange to show which items are visible (e.g., "Showing 1-10 of 100 results").
Page Size
Call setPageSize() to change items per page, here from a native select.
Note: Use
defaultPageSizefor the initial value when uncontrolled. UsepageSizeandonPageSizeChangeto control it.
Links
Set type="link" and pass getPageUrl for real navigation that crawlers can follow and users can open in a new tab.
Items and triggers render as anchors with the generated href:
To use a router's link component, pass it through asChild on the items and triggers. See the
Composition guide.
API Reference
Props
Root
Defines the <nav> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
boundaryCount | 1 | numberNumber of pages to show at the beginning and end |
count | numberTotal number of data items | |
defaultPage | 1 | numberThe initial active page when rendered. Use when you don't need to control the active page of the pagination. |
defaultPageSize | 10 | numberThe initial number of data items per page when rendered. Use when you don't need to control the page size of the pagination. |
getPageUrl | (details: PageUrlDetails) => stringFunction to generate href attributes for pagination links. Only used when `type` is set to "link". | |
ids | ElementIdsThe ids of the elements in the accordion. Useful for composition. | |
onPageChange | (details: PageChangeDetails) => voidCalled when the page number is changed | |
onPageSizeChange | (details: PageSizeChangeDetails) => voidCalled when the page size is changed | |
page | numberThe controlled active page | |
pageSize | numberThe controlled number of data items per page | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. | |
siblingCount | 1 | numberNumber of pages to show beside active page |
translations | IntlTranslationsSpecifies the localized strings that identifies the accessibility elements and their states | |
type | 'button' | 'button' | 'link'The type of the trigger element |
Ellipsis
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
index | number | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-pagination-ellipsis] | <uid> |
[data-index] | The index of the item |
FirstTrigger
Defines the <a> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-pagination-first-trigger] | <uid> |
[data-disabled] | Present when disabled |
Item
Defines the <a> element.
| Attribute | Default | Type |
|---|---|---|
type | 'page' | |
value | number | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<PaginationItemState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-pagination-item] | <uid> |
[data-index] | The index of the item |
[data-selected] | Present when selected |
LastTrigger
Defines the <a> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-pagination-last-trigger] | <uid> |
[data-disabled] | Present when disabled |
NextTrigger
Defines the <a> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-pagination-next-trigger] | <uid> |
[data-disabled] | Present when disabled |
PrevTrigger
Defines the <a> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
RootProvider
Defines the <nav> element.
| Attribute | Default | Type |
|---|---|---|
value | UsePaginationReturn | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
Context
API
| Property | Type |
|---|---|
page | numberThe current page. |
count | numberThe total number of data items. |
pageSize | numberThe number of data items per page. |
totalPages | numberThe total number of pages. |
pages | PagesThe page range. Represented as an array of page numbers (including ellipsis) |
previousPage | number | nullThe previous page. |
nextPage | number | nullThe next page. |
pageRange | PageRangeThe page range. Represented as an object with `start` and `end` properties. |
type | "button" | "link"The type of the pagination controls. |
getPageUrl | (page: number) => string | undefinedReturns the url for the given page, or `undefined` when `getPageUrl` is not provided. |
slice | <V>(data: V[]) => V[]Function to slice an array of data based on the current page. |
setPageSize | (size: number) => voidFunction to set the page size. |
setPage | (page: number) => voidFunction to set the current page. |
goToNextPage | VoidFunctionFunction to go to the next page. |
goToPreviousPage | VoidFunctionFunction to go to the previous page. |
goToFirstPage | VoidFunctionFunction to go to the first page. |
goToLastPage | VoidFunctionFunction to go to the last page. |
getItemState | (props: ItemProps) => ItemStateReturns the state of a pagination item |