Pagination

A navigation component that allows users to browse through pages.

Loading...

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 defaultPageSize for the initial value when uncontrolled. Use pageSize and onPageSizeChange to control it.

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.

AttributeDefaultType
asChild
boolean

Use 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.
boundaryCount1
number

Number of pages to show at the beginning and end

count
number

Total number of data items

defaultPage1
number

The initial active page when rendered. Use when you don't need to control the active page of the pagination.

defaultPageSize10
number

The 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) => string

Function to generate href attributes for pagination links. Only used when `type` is set to "link".

ids
ElementIds

The ids of the elements in the accordion. Useful for composition.

onPageChange
(details: PageChangeDetails) => void

Called when the page number is changed

onPageSizeChange
(details: PageSizeChangeDetails) => void

Called when the page size is changed

page
number

The controlled active page

pageSize
number

The 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.

siblingCount1
number

Number of pages to show beside active page

translations
IntlTranslations

Specifies 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.

AttributeDefaultType
index
number

asChild
boolean

Use 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.

AttributeDescription
[data-pagination-ellipsis]<uid>
[data-index]The index of the item

FirstTrigger

Defines the <a> element.

AttributeDefaultType
asChild
boolean

Use 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.

AttributeDescription
[data-pagination-first-trigger]<uid>
[data-disabled]Present when disabled

Item

Defines the <a> element.

AttributeDefaultType
type
'page'

value
number

asChild
boolean

Use 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.

AttributeDescription
[data-pagination-item]<uid>
[data-index]The index of the item
[data-selected]Present when selected

LastTrigger

Defines the <a> element.

AttributeDefaultType
asChild
boolean

Use 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.

AttributeDescription
[data-pagination-last-trigger]<uid>
[data-disabled]Present when disabled

NextTrigger

Defines the <a> element.

AttributeDefaultType
asChild
boolean

Use 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.

AttributeDescription
[data-pagination-next-trigger]<uid>
[data-disabled]Present when disabled

PrevTrigger

Defines the <a> element.

AttributeDefaultType
asChild
boolean

Use 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.

AttributeDefaultType
value
UsePaginationReturn

asChild
boolean

Use 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

PropertyType
page
number

The current page.

count
number

The total number of data items.

pageSize
number

The number of data items per page.

totalPages
number

The total number of pages.

pages
Pages

The page range. Represented as an array of page numbers (including ellipsis)

previousPage
number | null

The previous page.

nextPage
number | null

The next page.

pageRange
PageRange

The page range. Represented as an object with `start` and `end` properties.

type
"button" | "link"

The type of the pagination controls.

getPageUrl
(page: number) => string | undefined

Returns 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) => void

Function to set the page size.

setPage
(page: number) => void

Function to set the current page.

goToNextPage
VoidFunction

Function to go to the next page.

goToPreviousPage
VoidFunction

Function to go to the previous page.

goToFirstPage
VoidFunction

Function to go to the first page.

goToLastPage
VoidFunction

Function to go to the last page.

getItemState
(props: ItemProps) => ItemState

Returns the state of a pagination item