# Pagination (/docs/pagination)





`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`](/docs/hooks/use-pagination), which you can use on its own to draw a pager of your own.

```tsx
import { Pagination } from '@42-central/ui-react/pagination';

<Pagination count={95} pageSize={10} />
```

## Playground [#playground]

<story.Playground />

## Total pages [#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.

<Preview align="block" code="&#x22;<Pagination count={95} pageSize={10} />\n<Pagination pages={4} />&#x22;">
  <div className="flex flex-col items-center gap-4">
    <Pagination count="95" pageSize="10" />

    <Pagination pages="4" />
  </div>
</Preview>

## Controlled [#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.

<Preview code="&#x22;const [page, setPage] = useState(3);\n\n<Pagination pages={10} page={page} onPageChange={setPage} />&#x22;">
  <PaginationControlledDemo />
</Preview>

## Siblings and boundaries [#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.

<Preview align="block" code="&#x22;<Pagination pages={40} defaultPage={20} siblings={0} boundaries={1} />\n<Pagination pages={40} defaultPage={20} />\n<Pagination pages={40} defaultPage={20} siblings={2} boundaries={2} />&#x22;">
  <div className="flex flex-col items-center gap-4">
    <Pagination pages="40" defaultPage="20" siblings="0" boundaries="1" />

    <Pagination pages="40" defaultPage="20" />

    <Pagination pages="40" defaultPage="20" siblings="2" boundaries="2" />
  </div>
</Preview>

## Controls [#controls]

Previous and next are on by default (`withControls={false}` removes them). `withEdges` adds first and last.

<story.Preview variant="With edges" />

## Compact display [#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.

<story.Preview variant="Compact" />

## Variants and colors [#variants-and-colors]

The current page takes `variant` × `color`, as a [`Button`](/docs/button) does: `filled` by default, then `light`, `outline`, `subtle`, and `default`, [`ActionIcon`](/docs/action-icon)'s inverse fill. The other pages and the controls stay neutral, so the current page is the only accent.

<Preview align="block" code="&#x22;<Pagination pages={7} defaultPage={3} />\n<Pagination pages={7} defaultPage={3} variant=\&#x22;light\&#x22; color=\&#x22;green\&#x22; />\n<Pagination pages={7} defaultPage={3} variant=\&#x22;outline\&#x22; color=\&#x22;neutral\&#x22; />\n<Pagination pages={7} defaultPage={3} variant=\&#x22;subtle\&#x22; color=\&#x22;red\&#x22; />\n<Pagination pages={7} defaultPage={3} variant=\&#x22;default\&#x22; />&#x22;">
  <div className="flex flex-col items-center gap-3">
    <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" />
  </div>
</Preview>

## Sizes [#sizes]

`size` runs from `xs` to `xl`, the heights of `ActionIcon`, so a pager lines up with the toolbar it sits in.

<Preview align="block" code="&#x22;<Pagination pages={7} defaultPage={3} size=\&#x22;xs\&#x22; />\n<Pagination pages={7} defaultPage={3} size=\&#x22;md\&#x22; />\n<Pagination pages={7} defaultPage={3} size=\&#x22;xl\&#x22; />&#x22;">
  <div className="flex flex-col items-center gap-3">
    <Pagination pages="7" defaultPage="3" size="xs" />

    <Pagination pages="7" defaultPage="3" size="md" />

    <Pagination pages="7" defaultPage="3" size="xl" />
  </div>
</Preview>

## A list paged on the client [#a-list-paged-on-the-client]

With `count` and `pageSize`, [`usePagination`](/docs/hooks/use-pagination)'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.

<Preview align="block" code="&#x22;const [page, setPage] = useState(1);\nconst { range } = usePagination({ count: students.length, pageSize: 5, page });\n\n<ul>{students.slice(range.from - 1, range.to).map(…)}</ul>\n<span>{range.from}–{range.to} of {students.length}</span>\n<Pagination count={students.length} pageSize={5} page={page} onPageChange={setPage} />&#x22;">
  <PaginationListDemo />
</Preview>

## Links [#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`](/docs/hooks/use-link-component), 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`.

<Preview code="&#x22;// Next.js: app/blog/page.tsx\n<LinkComponentProvider component={Link}>\n  <Pagination\n    pages={20}\n    page={Number(searchParams.page ?? 1)}\n    getPageUrl={(page) => `/blog?page=${page}`}\n    withEdges\n  />\n</LinkComponentProvider>&#x22;">
  <PaginationLinkDemo />
</Preview>

## Icons [#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.

<Preview align="block" code="&#x22;<Pagination\n  pages={9}\n  defaultPage={4}\n  icons={{\n    prev: <ArrowLeft className={cn(iconStroke, \&#x22;rtl:-scale-x-100\&#x22;)} />,\n    next: <ArrowRight className={cn(iconStroke, \&#x22;rtl:-scale-x-100\&#x22;)} />,\n  }}\n/>&#x22;">
  <Pagination
    pages="9"
    defaultPage="4"
    icons="{
    prev: <ArrowLeft className={`${iconStroke} rtl:-scale-x-100`} />,
    next: <ArrowRight className={`${iconStroke} rtl:-scale-x-100`} />,
  }"
  />
</Preview>

## Translations and numbers [#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`](/docs/intl), which are the ones to print: the page items themselves read `١٢` under `ar-EG`.

```tsx
<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 [#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.

<Preview align="block" code="&#x22;<Pagination.Root pages={12} defaultPage={6} className=\&#x22;w-full justify-between\&#x22;>\n  <Pagination.Prev className=\&#x22;gap-1 px-3\&#x22;>\n    <ArrowLeft /> Previous\n  </Pagination.Prev>\n  <div className=\&#x22;flex gap-1\&#x22;>\n    <Pagination.Items />\n  </div>\n  <Pagination.Next className=\&#x22;gap-1 px-3\&#x22;>\n    Next <ArrowRight />\n  </Pagination.Next>\n</Pagination.Root>&#x22;">
  <PaginationCompositionDemo />
</Preview>

## Anatomy [#anatomy]

* **`Pagination.Root`**: the `<nav>` landmark, which holds the state the parts share.
* **`Pagination.Items`**: every page item and ellipsis, from `usePagination`'s `items`. It renders with `display: 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`*&#x2A;, &#x2A;*`.Prev`*&#x2A;, &#x2A;*`.Next`*&#x2A;, &#x2A;*`.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]

`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](/docs/testing).

## API [#api]

### `Pagination` [#pagination]

<TypeTable
  type="{
  count: { type: 'number', description: 'How many items there are. With pageSize, sets the page count. Exclusive with pages.' },
  pageSize: { type: 'number', default: '10', description: 'How many items one page holds.' },
  pages: { type: 'number', description: 'How many pages there are, when you know it directly. Exclusive with count.' },
  page: { type: 'number', description: 'The current page, 1-based, when you control it.' },
  defaultPage: { type: 'number', default: '1', description: 'The page to start on when uncontrolled.' },
  onPageChange: { type: '(page: number) => void', description: 'Called with the next page when it changes.' },
  siblings: { type: 'number', default: '1', description: 'Pages visible on each side of the current one.' },
  boundaries: { type: 'number', default: '1', description: 'Pages visible at each end of the bar.' },
  display: { type: '&#x22;pages&#x22; | &#x22;compact&#x22;', default: '&#x22;pages&#x22;', description: 'A button per page, or &#x22;Page 3 of 12&#x22; between the controls.' },
  withControls: { type: 'boolean', default: 'true', description: 'Draws the previous and next controls.' },
  withEdges: { type: 'boolean', default: 'false', description: 'Draws the first and last controls.' },
  size: { type: '&#x22;xs&#x22; | &#x22;sm&#x22; | &#x22;md&#x22; | &#x22;lg&#x22; | &#x22;xl&#x22;', default: '&#x22;md&#x22;', description: 'Height of every item and control.' },
  variant: { type: '&#x22;filled&#x22; | &#x22;light&#x22; | &#x22;outline&#x22; | &#x22;subtle&#x22; | &#x22;default&#x22;', default: '&#x22;filled&#x22;', description: &#x22;Shape of the current page, as on Button. default is ActionIcon's inverse fill.&#x22; },
  color: { type: 'Color', description: 'Palette of the current page.' },
  disabled: { type: 'boolean', default: 'false', description: 'Dims every item and control and ignores presses. Links lose their href.' },
  getPageUrl: { type: '(page: number) => string', description: &#x22;Makes every page a link to this URL, through LinkComponentProvider's component or a plain <a>.&#x22; },
  translations: { type: 'PaginationTranslations', description: 'Overrides the built-in strings. See below.' },
  icons: { type: '{ first?, prev?, next?, last?, ellipsis?: ReactNode }', description: 'Replaces the default icons. A missing or undefined key keeps the default.' },
  classNames: { type: '{ item?, control?, ellipsis?, label? }', description: 'A class per part, on top of the kit’s.' },
  testId: { type: 'string', description: 'Renders as data-testid on the <nav>; the parts take suffixed ids (see Anatomy).' },
}"
/>

`Pagination` accepts every `nav` prop too. `Pagination.Root` takes the same props except `display`, `withControls`, `withEdges` and `classNames`, plus `asChild`.

### `translations` [#translations]

<TypeTable
  type="{
  navigation: { type: 'string', default: '&#x22;Pagination&#x22;', description: 'The <nav> landmark’s accessible name.' },
  firstPage: { type: 'string', default: '&#x22;First page&#x22;', description: 'Accessible name of the first-page control.' },
  previousPage: { type: 'string', default: '&#x22;Previous page&#x22;', description: 'Accessible name of the previous-page control.' },
  nextPage: { type: 'string', default: '&#x22;Next page&#x22;', description: 'Accessible name of the next-page control.' },
  lastPage: { type: 'string', default: '&#x22;Last page&#x22;', description: 'Accessible name of the last-page control.' },
  page: { type: '({ page, total, formatted }) => string', default: '&#x22;Page 3&#x22;', description: 'Accessible name of each page item.' },
  label: { type: '({ page, total, formatted }) => ReactNode', default: '&#x22;Page 3 of 12&#x22;', description: 'The compact display’s text.' },
}"
/>

### Parts [#parts]

<TypeTable
  type="{
  'Pagination.Item': { type: '{ value: number } & button props', description: 'One page. children replace the page number.' },
  'Pagination.Ellipsis': { type: '{ index: number } & div props', description: 'A run of hidden pages. children replace the icon.' },
  'Pagination.Items': { type: '{ classNames?: { item?, ellipsis? } } & div props', description: 'Every item and ellipsis. No asChild.' },
  'Pagination.First / Prev / Next / Last': { type: 'button props', description: 'The controls. children replace the icon.' },
  'Pagination.Label': { type: 'span props', description: 'The compact display. children replace the text.' },
}"
/>

## Accessibility [#accessibility]

* The root is a `<nav>` landmark named by `translations.navigation`.
* Each page item is named "Page 3" (`translations.page`), and the current one carries `aria-current="page"`.
* The controls are named by their translations. On a button, one with nowhere to go is `disabled`; on a link, it has no `href` and carries `aria-disabled="true"`.
* The ellipses are `aria-hidden`: the pages around them carry the content.
* `Pagination.Label` is a `role="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 an `IntlProvider` with an RTL locale), the row runs right to left and the kit's arrows mirror.
