Move between pages of results. Use the ready-made Paginator for state-driven lists with automatic ellipses, a compact "Page x of y" mode and two sizes, or compose link-based pagination where every page has its own URL. Exports the getPageRange helper behind the ellipsis logic.
siblings sets how many pages are shown on each side of the current page (default 1). The first and last pages are always shown, and a gap becomes an ellipsis.
When every page fits (pageCount up to siblings * 2 + 5, so 7 by default), all numbers are shown with no ellipsis. Previous is disabled on the first page and Next on the last.
import { useState } from "react";import { Paginator } from "@/components/ui/pagination";export default function PaginationFewPages() { const [page, setPage] = useState(1); return <Paginator page={page} pageCount={5} onPageChange={setPage} />;}
Build the page list with getPageRange(page, pageCount, siblings?), which returns numbers and "ellipsis" markers, and disable Previous and Next at the ends with isDisabled. Wrap the app in React Aria's RouterProvider so the links use client-side navigation. The preview uses a local stand-in for the router.
import { useState } from "react";import { RouterProvider } from "react-aria-components";import { getPageRange, Pagination, PaginationContent, PaginationEllipsis, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious,} from "@/components/ui/pagination";const pageCount = 24;export default function PaginationLinksRouter() { // Stand-in for your router. In Next.js read `useSearchParams()` and pass // `useRouter().push` to RouterProvider in your app's providers. const [page, setPage] = useState(1); const href = (p: number) => `?page=${p}`; return ( <RouterProvider navigate={(to) => setPage(Number(new URLSearchParams(to).get("page")))} > <Pagination> <PaginationContent> <PaginationItem> <PaginationPrevious href={href(page - 1)} isDisabled={page <= 1} /> </PaginationItem> {getPageRange(page, pageCount).map((p, i) => p === "ellipsis" ? ( // biome-ignore lint/suspicious/noArrayIndexKey: at most two ellipses <PaginationItem key={`e${i}`}> <PaginationEllipsis /> </PaginationItem> ) : ( <PaginationItem key={p}> <PaginationLink href={href(p)} isActive={p === page} aria-label={`Page ${p}`} > {p} </PaginationLink> </PaginationItem> ), )} <PaginationItem> <PaginationNext href={href(page + 1)} isDisabled={page >= pageCount} /> </PaginationItem> </PaginationContent> </Pagination> </RouterProvider> );}
With the Next.js App Router, read the page from the URL:
app/invoices/page.tsxtsx
import { InvoicePagination } from "./invoice-pagination";export default async function Page({ searchParams }: { searchParams: Promise<{ page?: string }> }) { const page = Number((await searchParams).page ?? 1); // …fetch the rows for `page` return <InvoicePagination page={page} pageCount={24} />;}
InvoicePagination is a client component that renders the parts as in the preview, with an href of ?page=N for each page. Your app's RouterProvider passes router.push as navigate.
A rows-per-page Select, a range summary and a small paginator under a Table. Changing the page size resets to page 1. Pass className="mx-0 w-auto" to stop the paginator from centering itself.
Rendered in a <nav aria-label="pagination"> landmark. Pass your own aria-label (for example "Search results pages") when a page has more than one.
The current page has aria-current="page".
Paginator labels its buttons "Previous page", "Next page" and "Page 3"; the link parts label Previous and Next "Go to previous page" and "Go to next page". Override any of them with aria-label.
Previous and Next are disabled (and removed from the tab order) at the ends.
Ellipses are aria-hidden.
After changing pages in client-side lists, consider moving focus to the top of the results or announcing the change, so screen-reader users know the content updated.
Items use buttonVariants, so they follow button tones and radii. Page numbers are tabular-nums so widths don't shift.
className on Pagination or Paginator styles the <nav>. It's centered with mx-auto flex w-full justify-center; use justify-start, justify-end or mx-0 w-auto to align it.
Returns (number | "ellipsis")[]: always the first and last page, the current page with its siblings, and "ellipsis" for each gap. When pageCount is at most siblings * 2 + 5, returns every page.