Skip to Content
Cristal

Navigation and progress

Pagination

Page numbers, previous and next page, as real links.

<cr-pagination>CrPagination

Example

cr-pagination shows the current page (from 1) among total pages: the first and last ones, the current page and its neighbours, and "…" in place of the others (1 … 4 5 6 … 20). A ringed highlight marks the current page; it slides to the new number when the page changes.

With href, every page is a real link: {page} is replaced by the number (/products?page={page}). Ctrl/Cmd+click, middle click and "Open in new tab" work as on any link. Without href, they are buttons: onCrChange gives the chosen page, and you update page.

Page shown: 5

'use client';

import { useState } from 'react';
import { CrBox, CrPagination } from '@cristal-ui/react';

export default function PaginationBasic() {
  const [page, setPage] = useState(5);

  return (
    <CrBox display="flex" direction="column" gap="lg">
      <CrPagination page={7} total={42} href="/docs/composants/pagination?page={page}" />
      <CrPagination page={page} total={12} onCrChange={(event) => setPage(event.detail)} />
      <p>Page shown: {page}</p>
    </CrBox>
  );
}

If the user asked their system to reduce motion, the highlight jumps straight to the new page, without sliding.

Accessibility

  • The pagination is a navigation region (nav) named "Pagination", with a list of links or buttons.
  • Each number is named "Page 4"; the current page has aria-current="page". It also stands out without colour: bold, in a ringed highlight.
  • The arrows are named "Previous page" and "Next page"; on the first or last page they stay in place but are inactive (a link without an address, or a disabled button). If focus was on an arrow that becomes inactive, it moves to the current page.
  • The "…" are decorative, hidden from screen readers.
  • Everything works from the keyboard with Tab, Enter (and Space for buttons).

API

Properties

PropertyTypeDefaultDescription
hrefstring—Adresse des pages, où {page} est remplacé par le numéro (« /produits?page={page} ») : les pages deviennent des liens.
pagenumber1Page courante, à partir de 1.
totalnumber1Nombre de pages.

Events

Reactevent.detailDescription
onCrChangenumberÉmis au choix d'une page, sans href ; detail : le numéro de la page.

CSS parts

To style it from outside: cr-pagination::part(name) { … }

PartDescription
nextLe lien ou bouton « Page suivante ».
pageUn numéro de page.
previousLe lien ou bouton « Page précédente ».
thumbLa pastille qui glisse sous la page courante.

On this page