Pager
The previous and next links at the foot of a docs page or blog post. Two outline cards that walk the reader through your content in order, with an arrow that leans the way it goes.
Installation#
Usage#
Put a Pager at the end of the article with a PagerItem for each neighbour. It is for walking content in order; for numbered pages of a table or a list, use Pagination.
import { Pager, PagerItem } from "@/components/ui/pager"
export function ArticleFooter({ previous, next }: { previous?: Page; next?: Page }) {
return (
<Pager>
{previous ? <PagerItem direction="previous" href={previous.href} title={previous.title} /> : null}
{next ? <PagerItem direction="next" href={next.href} title={next.title} /> : null}
</Pager>
)
}Anatomy#
import { Pager, PagerItem } from "@/components/ui/pager"
<Pager>
<PagerItem direction="previous" />
<PagerItem direction="next" />
</Pager>First and last page#
Each side is optional. Leave out the link that does not exist: on the first page the next link keeps to the right column, on the last page the previous link keeps to the left, so the pair never jumps sides from one page to the next. On a phone both stack full width.
Description#
Add a description to say what the next page is about, which suits blog posts and long guides. It wraps to two lines at most.
With Next.js Link#
A PagerItem renders a plain <a> for an href. For client-side navigation and prefetching, pass asChild and give it your router's link as the only child. The card look, the arrow and rel move onto that link.
Labels#
Rename the small line with label, for a course or a series. The defaults come from LabelsProvider, so a translated app gets them in its own language with no props.
API reference#
Pager
The <nav> landmark that lays out the two links: one column on narrow screens, two from sm. Forwards all native <nav> props and accepts className, merged last.
| Prop | Type | Default | Description |
|---|---|---|---|
| aria-label | string | "Pagination" | Names the landmark. Falls back to pagination from the nearest LabelsProvider, then English. Give it a distinct name when the page has another pagination nav. |
| Data attribute | Description |
|---|---|
| data-slot | "pager". |
PagerItem
One link, drawn as an interactive outline Card: a direction label, the page title and an optional description beside an arrow. Renders an <a> and forwards its props (href, target, onClick), or slots onto your own link with asChild.
| Prop | Type | Default | Description |
|---|---|---|---|
| direction* | "previous" | "next" | - | Which way the link goes. Sets the arrow, the default label and rel, and places a next link in the right column, so it stays right when it is alone. |
| title* | React.ReactNode | - | The title of the page the link goes to. |
| description | React.ReactNode | - | A line under the title, clamped to two lines. |
| label | React.ReactNode | "Previous page" | "Next page" | The small line above the title. Falls back to previousPage / nextPage from the nearest LabelsProvider, then English. |
| href | string | - | Where the link goes when it renders its own <a>. |
| asChild | boolean | false | Merge onto the single child element instead, such as a Next.js Link. The child keeps its own props; the arrow and the text are rendered inside it. |
| Data attribute | Description |
|---|---|
| data-slot | "pager-item" on the link; "pager-arrow", "pager-label", "pager-title" and "pager-description" on its parts. |
| data-direction | "previous" or "next". |