Pagination
Move through pages of results. Numbers, previous and next, with ellipses when there are too many pages to show. The current page is marked for assistive tech with aria-current. Pagination only moves between pages; it does not load them. Pair it with your data or a DataTable.
Install
npx shadcn@latest add @nelumbo/paginationControlled
The page lives in your state. Previous and Next stop at the ends (aria-disabled keeps them focusable so the focus does not jump). The status line is announced when the page changes.
Page 3 of 8
Many pages
paginationRange(page, count, siblings) gives the numbers to render, with ellipses where pages are skipped. siblings sets how many numbers show either side of the current page.
Siblings 1, page 21 of 42
Siblings 2, page 6 of 42
Compact
Icons only, for toolbars and tight spaces. Give the icon buttons an aria-label; the page links keep their numbers.
Sizes
size works as in shadcn: "sm", "default" and "lg" set the round target; "icon" is the square-ish icon-only size.
Usage
import { Pagination, PaginationContent, PaginationEllipsis, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious, paginationRange } from "@/components/ui/pagination"<Pagination> <PaginationContent> <PaginationItem> <PaginationPrevious href="?page=${page - 1}" aria-disabled={page === 1} /> </PaginationItem> {paginationRange(page, pageCount).map((p, i) => p === "ellipsis" ? ( <PaginationItem key={i}><PaginationEllipsis /></PaginationItem> ) : ( <PaginationItem key={p}> <PaginationLink href={`?page=${p}`} isActive={p === page}>{p}</PaginationLink> </PaginationItem> ) )} <PaginationItem> <PaginationNext href="?page=${page + 1}" aria-disabled={page === pageCount} /> </PaginationItem> </PaginationContent></Pagination>Props
| Prop | Type | Default | Notes |
|---|---|---|---|
Pagination | nav props | Labelled "pagination" | |
PaginationLink | a props, isActive, size, asChild | isActive sets aria-current="page" and moves the inverse pill to it with a spring | |
size | "sm" | "default" | "lg" | "icon" | "default" | Round target; icon is the icon-only size |
PaginationPrevious / PaginationNext | a props | Chevron and label; the label hides below sm | |
PaginationEllipsis | span props | Skipped pages; announced as More pages | |
paginationRange(page, pageCount, siblings) | (number | "ellipsis")[] | siblings = 1 | Pages to render, first and last always shown |