Skip to content

React Pagination Component

A React pagination component with page numbers, ellipses and first, previous, next and last buttons in a labeled navigation landmark.

npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/pagination.json

Results 1 to 10

Controlled pagination

Page numbers with ellipses; first, previous, next and last buttons.

Current page: 6

Files to copy

5 folders · 6 files · 3 packages
From theme/src/
  • components/pagination/
  • hooks/{use-controllable.ts, use-media-query.ts, use-preferences.ts}
  • motion/tokens.ts
  • lib/{cn.ts, warn-once.ts}
  • styles/
shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/pagination.jsonRegistry item: pagination. The styles need the Tailwind v4 glass UI setup.
Packages
pnpm add clsx motion tailwind-merge

Props

PropTypeDefaultDescription
pagenumberNoneSets the current page, 1-based, when controlled.
defaultPagenumber1Sets the starting page when uncontrolled.
onPageChange((page: number) => void)NoneCalled with the new 1-based page.
pageCount (required)numberNoneTotal number of pages. 0 is treated as 1.
siblingCountnumber1Pages shown on each side of the current one.
boundaryCountnumber1Pages always shown at the start and the end.
showFirstLastbooleantrueShows the first-page and last-page buttons.
showPrevNextbooleantrueShows the previous and next buttons.
size"sm" | "md""md"Button size: "sm" (32px) or "md" (40px, default).
disabledbooleanfalseDisables every button of the pagination.
getPageHref((page: number) => string)NoneRender page links instead of buttons (crawlable, open in new tab). With onPageChange as well, clicks are handled in-app (the browser's own navigation is prevented).
labelsPartial<PaginationLabels>defaultPaginationLabelsEvery other string, for translation: labels={{ nav: "…" }}; omitted keys keep the English of defaultPaginationLabels. All 8 keys of PaginationLabels are listed in the key table under the props table.
classNamestringNoneAdds a class name to the <nav> element.
idstringNoneSets the id attribute of the <nav> element.
aria-labelstringNoneOverrides labels.nav. Give each pagination on a page its own name.
PaginationLabels keys and English defaults (8)
Pass any key in labels; the rest keep the defaults of defaultPaginationLabels.
KeyEnglish default
navPagination
firstFirst page
previousPrevious page
nextNext page
lastLast page
page(page) => `Page ${page}`
morePagesMore pages
pageOf(page, pageCount) => `Page ${page} of ${pageCount}`

When to use pagination

Use pagination under a long list or table when people need to know where they are and jump to a position: search results, an orders table, an admin list. The data table already uses it in its footer. Prefer infinite scroll or a load-more button only when position does not matter, and prefer a combobox with search when the goal is finding one item.

Keep the page size predictable: a bar with seven slots (first and last page, the current one with a neighbor on each side, and two ellipses) fits a phone, and on small screens the control switches to the compact "Page 3 of 32" text. Disable it while a request is in flight so a second click cannot start a second request, and reset to page 1 whenever a filter changes.

Pair it with the React data table for server-side paging, with skeleton rows while a page loads, and with breadcrumbs for orientation.

Frequently asked questions

All exports on this page

  • Pagination — Pagination: page numbers with ellipses, first / previous / next / last, in a labelled <nav> landmark.
  • defaultPaginationLabels — Default English strings of PaginationLabels; spread it and override single keys to reword.
  • getPageItems — The page slots to show (1-based).

Keyboard

KeysAction
Tab/Shift + TabMove between the first, previous, page, next and last controls.
Enter/SpaceGo to the focused page (a button). With getPageHref the items are links: Enter follows the link.
Edge arrowsPrevious on page 1 and Next on the last page stay focusable but do nothing (aria-disabled), so focus never drops to the page body.

Accessibility

  • The control is a <nav> landmark named “Pagination”; give each pagination on a page its own aria-label.
  • The current page has aria-current="page"; every page button is named “Page 3”, and ellipses read “More pages”.
  • While disabled, nothing can be activated; on touch the targets are 44px; every string is in labels.

67 components pages in all: browse them on All components.

By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .