Pagination
A row of page buttons or links with previous/next controls, on Ark's pagination machine. Ellipses, a compact "Page 3 of 12" display, link mode for crawlable pages, and the usePagination hook underneath.
Pagination moves through a list that is split into pages: a button per page, with an ellipsis wherever pages are hidden, between previous and next controls. Ark's pagination machine supplies the ARIA and the link hrefs; the page state and the ellipsis math come from usePagination, which you can use on its own to draw a pager of your own.
import { Pagination } from '@42-central/ui-react/pagination';
<Pagination count={95} pageSize={10} />Playground
Component
Dir
Presets
Props
Code
<Component
pages={12}
siblings={1}
boundaries={1}
display="pages"
variant="filled"
size="md"
withControls
/>Total pages
Give the total as count (how many items there are) and pageSize (how many fit on a page, 10 by default), or as pages when you already know the page count. Pages are 1-based everywhere, as they're printed.
Code
<Pagination count={95} pageSize={10} />
<Pagination pages={4} />Controlled
page and onPageChange control the page; defaultPage sets where an uncontrolled one starts. onPageChange gets the page number, not an event, and only fires for a real move: pressing the current page, or Previous on page 1, does nothing.
Current page: 3
Code
const [page, setPage] = useState(3);
<Pagination pages={10} page={page} onPageChange={setPage} />Siblings and boundaries
siblings is how many pages stay visible on each side of the current one, and boundaries how many at each end. Both default to 1. Once there are more pages than slots, the bar keeps the same number of slots wherever the page is, and an ellipsis that would hide a single page shows that page instead, so the bar never shifts under the pointer.
Code
<Pagination pages={40} defaultPage={20} siblings={0} boundaries={1} />
<Pagination pages={40} defaultPage={20} />
<Pagination pages={40} defaultPage={20} siblings={2} boundaries={2} />Controls
Previous and next are on by default (withControls={false} removes them). withEdges adds first and last.
Compact display
Where a row of pages doesn't fit, display="compact" replaces it with "Page 5 of 12" between the controls. The text is a polite live region, so a screen reader announces the new page while focus stays on Next.
Variants and colors
The current page takes variant × color, as a Button does: filled by default, then light, outline, subtle, and default, ActionIcon's inverse fill. The other pages and the controls stay neutral, so the current page is the only accent.
Code
<Pagination pages={7} defaultPage={3} />
<Pagination pages={7} defaultPage={3} variant="light" color="green" />
<Pagination pages={7} defaultPage={3} variant="outline" color="neutral" />
<Pagination pages={7} defaultPage={3} variant="subtle" color="red" />
<Pagination pages={7} defaultPage={3} variant="default" />Sizes
size runs from xs to xl, the heights of ActionIcon, so a pager lines up with the toolbar it sits in.
Code
<Pagination pages={7} defaultPage={3} size="xs" />
<Pagination pages={7} defaultPage={3} size="md" />
<Pagination pages={7} defaultPage={3} size="xl" />A list paged on the client
With count and pageSize, usePagination's range gives the first and last item on the page (1-based), which is both the "1–5 of 47" line and the slice to show.
- Student 01
- Student 02
- Student 03
- Student 04
- Student 05
Code
const [page, setPage] = useState(1);
const { range } = usePagination({ count: students.length, pageSize: 5, page });
<ul>{students.slice(range.from - 1, range.to).map(…)}</ul>
<span>{range.from}–{range.to} of {students.length}</span>
<Pagination count={students.length} pageSize={5} page={page} onPageChange={setPage} />Links
For pages a crawler should follow, or a page number that lives in the URL, pass getPageUrl: every page and control becomes a link to that URL. They render through the component of your LinkComponentProvider, so navigation stays client-side, and as plain <a> without one. Read the page back from the URL and pass it as page.
A control with nowhere to go (Previous on page 1) is an <a role="link" aria-disabled="true"> with no href, never your router's Link, since most of them require an href.
The router went to /blog?page=4
Code
// Next.js: app/blog/page.tsx
<LinkComponentProvider component={Link}>
<Pagination
pages={20}
page={Number(searchParams.page ?? 1)}
getPageUrl={(page) => `/blog?page=${page}`}
withEdges
/>
</LinkComponentProvider>Icons
icons replaces any of first, prev, next, last and ellipsis. The kit's arrows flip under RTL; yours are drawn as given, so add rtl:-scale-x-100 to a directional icon, and className={iconStroke} (from @42/ui-react) for the kit's 1.5px line.
Code
<Pagination
pages={9}
defaultPage={4}
icons={{
prev: <ArrowLeft className={cn(iconStroke, "rtl:-scale-x-100")} />,
next: <ArrowRight className={cn(iconStroke, "rtl:-scale-x-100")} />,
}}
/>Translations and numbers
translations overrides every built-in string; English ships as the default, and a partial object only replaces the keys you set. The two function keys get the page numbers raw (page, total, for plural rules) and formatted for the locale of the nearest IntlProvider, which are the ones to print: the page items themselves read ١٢ under ar-EG.
<Pagination
pages={12}
display="compact"
translations={{
navigation: 'Pagination',
firstPage: 'Première page',
previousPage: 'Page précédente',
nextPage: 'Page suivante',
lastPage: 'Dernière page',
page: ({ formatted }) => `Page ${formatted.page}`,
label: ({ formatted }) => `Page ${formatted.page} sur ${formatted.total}`,
}}
/>Composition
For a layout the props don't cover, compose the parts inside Pagination.Root, which takes the same total, page, size, variant, color, getPageUrl, translations and icons props. A control's children replace its icon.
Code
<Pagination.Root pages={12} defaultPage={6} className="w-full justify-between">
<Pagination.Prev className="gap-1 px-3">
<ArrowLeft /> Previous
</Pagination.Prev>
<div className="flex gap-1">
<Pagination.Items />
</div>
<Pagination.Next className="gap-1 px-3">
Next <ArrowRight />
</Pagination.Next>
</Pagination.Root>Anatomy
Pagination.Root: the<nav>landmark, which holds the state the parts share.Pagination.Items: every page item and ellipsis, fromusePagination'sitems. It renders withdisplay: contents, so the items sit in the root's own row.Pagination.Item: one page (value, 1-based). Its content is the page number, formatted for the locale.Pagination.Ellipsis: a run of hidden pages (index, its position among the items). Decorative.Pagination.First,.Prev,.Next,.Last: the controls.Pagination.Label: the compact display's "Page 3 of 12", a live region.
Every part but Items takes asChild and renders as its only child, with the part's content inside it.
testId
testId on Pagination lands on the <nav>, and each part takes it with a suffix: ${testId}-first, -prev, -next, -last, -label and -items, and each page ${testId}-items-page-${n}. In a composed layout, every part takes its own testId. See Testing.
API
Pagination
Prop
Type
Pagination accepts every nav prop too. Pagination.Root takes the same props except display, withControls, withEdges and classNames, plus asChild.
translations
Prop
Type
Parts
Prop
Type
Accessibility
- The root is a
<nav>landmark named bytranslations.navigation. - Each page item is named "Page 3" (
translations.page), and the current one carriesaria-current="page". - The controls are named by their translations. On a button, one with nowhere to go is
disabled; on a link, it has nohrefand carriesaria-disabled="true". - The ellipses are
aria-hidden: the pages around them carry the content. Pagination.Labelis arole="status"live region, so the compact display announces each page turn while focus stays on the control that moved it.- Under RTL (
dir="rtl", or anIntlProviderwith an RTL locale), the row runs right to left and the kit's arrows mirror.