Molecules · Pagination
Pagination
Moves through a long list one page at a time. The current page takes the neutral selected look, a selected surface with a 2px signal underline. Where there are too many pages to fit, a gap stands in for the run that's hidden.
- Best for
- Moving through a long list or table one page at a time.
- Not for
- Steps in a form: use Stepper. Fewer than two pages: don't render anything.
This page as Markdown, a plain-text copy for a coding agent (an AI tool that writes code).
Examples
Few pages
Code
tsx
<Pagination page={2} pageCount={5} onPageChange={() => {}} label="Pagination, few pages" />Many pages
Showing 1 to 20 of 400 depots
Code
tsx
function ManyPagesExample() { const [page, setPage] = useState(1) const perPage = 20 const total = 400 const from = (page - 1) * perPage + 1 const to = Math.min(page * perPage, total) return ( <div> <Pagination page={page} pageCount={20} onPageChange={setPage} label="Pagination, many pages" /> <p className="font-mono text-xs text-[var(--color-text-muted)] mt-3"> Showing {from} to {to} of {total} depots </p> </div> )}<ManyPagesExample />Wider context: two page numbers on each side of the current page
Code
tsx
<Pagination page={10} pageCount={20} siblings={2} onPageChange={() => {}} label="Pagination, wider context"/>First and last
Code
tsx
function Live(props: Omit<Parameters<typeof Pagination>[0], 'page' | 'onPageChange'>) { const [page, setPage] = useState(4) return <Pagination {...props} page={page} onPageChange={setPage} />}<Live pageCount={20} showFirstLast label="Pagination, first and last" />With labels
Code
tsx
function Live(props: Omit<Parameters<typeof Pagination>[0], 'page' | 'onPageChange'>) { const [page, setPage] = useState(4) return <Pagination {...props} page={page} onPageChange={setPage} />}<Live pageCount={20} showLabels label="Pagination, with labels" />Compact
Code
tsx
function Live(props: Omit<Parameters<typeof Pagination>[0], 'page' | 'onPageChange'>) { const [page, setPage] = useState(4) return <Pagination {...props} page={page} onPageChange={setPage} />}<Live variant="compact" pageCount={20} showFirstLast label="Pagination, compact" />Page select
Code
tsx
function Live(props: Omit<Parameters<typeof Pagination>[0], 'page' | 'onPageChange'>) { const [page, setPage] = useState(4) return <Pagination {...props} page={page} onPageChange={setPage} />}<Live variant="select" pageCount={12} label="Pagination, page select" />Go to page
Code
tsx
function Live(props: Omit<Parameters<typeof Pagination>[0], 'page' | 'onPageChange'>) { const [page, setPage] = useState(4) return <Pagination {...props} page={page} onPageChange={setPage} />}<Live pageCount={48} showJump label="Pagination, go to page" />Table footer
Code
tsx
function TableFooterExample() { const total = 397 const [page, setPage] = useState(2) const [pageSize, setPageSize] = useState(20) return ( <div className="w-full"> <Pagination page={page} pageCount={Math.ceil(total / pageSize)} onPageChange={setPage} totalItems={total} pageSize={pageSize} onPageSizeChange={size => { setPageSize(size) setPage(1) }} showFirstLast label="Pagination, table footer" /> </div> )}<TableFooterExample />Anatomy
| Part | What it is |
|---|---|
| nav | The navigation region, named 'Pagination'. |
| Previous / Next | Ghost IconButtons (icon-only buttons with no fill). At the first and last page they're aria-disabled rather than disabled. ARIA (Accessible Rich Internet Applications) attributes tell screen readers about a control, and aria-disabled only marks the button as unavailable. It stays a real stop when you press Tab, so keyboard focus never drops to the page body when one stops working. |
| Page | A small Button named 'Page n', with tabular figures (digits that all take the same width). |
| Current page | The neutral selected surface with primary text in semibold and a 2px signal underline, with aria-current=page so screen readers say it's the current one. It isn't disabled, so Tab still reaches it. |
| Gap | An ellipsis that stands for two or more hidden pages. It's aria-hidden, so screen readers skip it. |
| First / Last | Optional (showFirstLast). Ghost IconButtons, aria-disabled at the first and last page. |
| Readout or page Select | Takes the place of the page buttons when variant is 'compact' or 'select'. |
| Range and rows per page | Optional (totalItems, pageSize, onPageSizeChange). These turn the control into a table footer: the range at the start, the controls at the end. |
| Go to page | Optional (showJump). A small number Input with a visible label, and a Go button. |
Props
- pagenumber
- Counts from 1. A number outside the range is pulled back into it.
- pageCountnumber
- Below 1, nothing renders.
- onPageChange(page: number) => void
- It's never called with the page you're already on.
- variant'numbered' | 'compact' | 'select'Default 'numbered'
- What sits between Previous and Next: the page buttons, a 'Page 3 of 20' readout (which screen readers announce politely, without interrupting, when it changes), or a page Select. Only use 'select' up to a few dozen pages.
- siblingsnumberDefault 1
- How many pages show on each side of the current page, for 'numbered'.
- showFirstLastbooleanDefault false
- Adds First page and Last page icon buttons at the ends. Like Previous and Next, they go aria-disabled at the first and last page.
- showLabelsbooleanDefault false
- Shows Previous and Next as text buttons ('Previous', 'Next') with their chevrons, instead of icons alone.
- showJumpbooleanDefault false
- Adds a 'Go to page' field. Enter or Go jumps there, and a number past either end goes to that end.
- totalItemsnumber
- Together with pageSize, it shows the range on view ('21–40 of 400') at the start and lays the control out as a table footer.
- pageSizenumber
- Items per page, used for the range text and the rows-per-page Select.
- onPageSizeChange(pageSize: number) => void
- Together with pageSize, it shows a rows-per-page Select. When it fires, reset page to 1: the old page may not exist any more.
- pageSizeOptionsnumber[]Default [10, 20, 50, 100]
- The rows-per-page choices.
- labelstringDefault 'Pagination'
- The name of the nav landmark (a region screen readers can jump to).
- classNamestring
- Added to the nav element.
- refRef<HTMLElement>
- Passed through to the nav DOM node (the element in the page).
Keyboard
| Keys | Result |
|---|---|
| Tab | Moves across Previous, each page, and Next. |
| EnterSpace | Goes to that page. |
| Enter | In the Go to page field, jumps to the page you typed. |
Do and don't
Do
- Say how many results there are somewhere near it: 'Showing 41 to 60 of 312'.
- After a change, move focus to the top of the new page of results.
- Keep siblings at 1 on narrow layouts.
- Under a data table, pass totalItems and pageSize. The footer then says what's on view, so you don't need a separate line of text.
- Use variant 'compact' where space is tight, such as a card or a phone layout.
Don't
- Don't paginate fewer than two pages; render nothing.
- Don't disable the current page; Tab would skip it.
- Don't use pagination for steps in a form.
- Don't use variant 'select' for hundreds of pages. A list that long needs showJump instead.
- Don't round the buttons into circles or pills; the square and the cut corner are this system's shape.