Get Started
Components
- Accordion
- Attachment
- Avatar
- Badge
- Breadcrumb
- Button
- Button Group
- Card
- Checkbox
- Code Block
- Collapsible
- Dialog
- Dropdown Menu
- Empty
- Field
- Hover Card
- Input
- Input Group
- Input OTP
- Item
- Label
- Marker
- Message
- Number Flow
- Pagination
- Popover
- Progress
- Radio Group
- Select
- Slider
- Sonner
- Spinner
- Switch
- Tooltip
- Separator
- Sheet
- Tabs
- Textarea
- Toggle
- Toggle Group
- Trace
AI Elements
Libraries
Utilities
import type { VariantProps } from "class-variance-authority";
import {
ChevronLeftIcon,
ChevronRightIcon,
MoreHorizontalIcon,
} from "lucide-react";
import type * as React from "react";
import { buttonVariants, cn } from "@/lib/utils";
function Pagination({ className, ...props }: React.ComponentProps<"nav">) {
return (
<nav
aria-label="pagination"
className={cn("mx-auto flex w-full justify-center", className)}
data-slot="pagination"
role="navigation"
{...props}
/>
);
}
function PaginationContent({
className,
...props
}: React.ComponentProps<"ul">) {
return (
<ul
className={cn("flex items-center gap-0.5", className)}
data-slot="pagination-content"
{...props}
/>
);
}
function PaginationItem({ ...props }: React.ComponentProps<"li">) {
return <li data-slot="pagination-item" {...props} />;
}
type PaginationLinkProps = {
isActive?: boolean;
} & Pick<VariantProps<typeof buttonVariants>, "size"> &
Omit<React.ComponentProps<"a">, "ref">;
function PaginationLink({
className,
isActive,
size = "icon",
href = "#",
...props
}: PaginationLinkProps) {
return (
<a
aria-current={isActive ? "page" : undefined}
className={cn(
buttonVariants({ size, variant: isActive ? "outline" : "ghost" }),
className
)}
data-active={isActive}
data-slot="pagination-link"
href={href}
{...props}
/>
);
}
function PaginationPrevious({
className,
text = "Previous",
...props
}: React.ComponentProps<typeof PaginationLink> & { text?: string }) {
return (
<PaginationLink
aria-label="Go to previous page"
className={cn("pl-1.5!", className)}
size="default"
{...props}
>
<ChevronLeftIcon data-icon="inline-start" />
<span className="hidden sm:block">{text}</span>
</PaginationLink>
);
}
function PaginationNext({
className,
text = "Next",
...props
}: React.ComponentProps<typeof PaginationLink> & { text?: string }) {
return (
<PaginationLink
aria-label="Go to next page"
className={cn("pr-1.5!", className)}
size="default"
{...props}
>
<span className="hidden sm:block">{text}</span>
<ChevronRightIcon data-icon="inline-end" />
</PaginationLink>
);
}
function PaginationEllipsis({
className,
...props
}: React.ComponentProps<"span">) {
return (
<span
aria-hidden
className={cn(
"flex size-8 items-center justify-center [&_svg:not([class*='size-'])]:size-4",
className
)}
data-slot="pagination-ellipsis"
{...props}
>
<MoreHorizontalIcon />
<span className="sr-only">More pages</span>
</span>
);
}
export {
Pagination,
PaginationContent,
PaginationEllipsis,
PaginationItem,
PaginationLink,
PaginationNext,
PaginationPrevious,
};Pagination splits long content into pages. It composes standard links so navigation works with keyboard, screen readers, and browser history.
Installation
$ bunx --bun frakment add pagination$ npx frakment add pagination$ pnpm dlx frakment add pagination$ yarn dlx frakment add pagination
Install the base button:
$ bunx --bun frakment add button$ npx frakment add button$ pnpm dlx frakment add button$ yarn dlx frakment add button
Copy and paste the following code into your project.
import type { VariantProps } from "class-variance-authority";
import {
ChevronLeftIcon,
ChevronRightIcon,
MoreHorizontalIcon,
} from "lucide-react";
import type * as React from "react";
import { buttonVariants, cn } from "@/lib/utils";
function Pagination({ className, ...props }: React.ComponentProps<"nav">) {
return (
<nav
aria-label="pagination"
className={cn("mx-auto flex w-full justify-center", className)}
data-slot="pagination"
role="navigation"
{...props}
/>
);
}
function PaginationContent({
className,
...props
}: React.ComponentProps<"ul">) {
return (
<ul
className={cn("flex items-center gap-0.5", className)}
data-slot="pagination-content"
{...props}
/>
);
}
function PaginationItem({ ...props }: React.ComponentProps<"li">) {
return <li data-slot="pagination-item" {...props} />;
}
type PaginationLinkProps = {
isActive?: boolean;
} & Pick<VariantProps<typeof buttonVariants>, "size"> &
Omit<React.ComponentProps<"a">, "ref">;
function PaginationLink({
className,
isActive,
size = "icon",
href = "#",
...props
}: PaginationLinkProps) {
return (
<a
aria-current={isActive ? "page" : undefined}
className={cn(
buttonVariants({ size, variant: isActive ? "outline" : "ghost" }),
className
)}
data-active={isActive}
data-slot="pagination-link"
href={href}
{...props}
/>
);
}
function PaginationPrevious({
className,
text = "Previous",
...props
}: React.ComponentProps<typeof PaginationLink> & { text?: string }) {
return (
<PaginationLink
aria-label="Go to previous page"
className={cn("pl-1.5!", className)}
size="default"
{...props}
>
<ChevronLeftIcon data-icon="inline-start" />
<span className="hidden sm:block">{text}</span>
</PaginationLink>
);
}
function PaginationNext({
className,
text = "Next",
...props
}: React.ComponentProps<typeof PaginationLink> & { text?: string }) {
return (
<PaginationLink
aria-label="Go to next page"
className={cn("pr-1.5!", className)}
size="default"
{...props}
>
<span className="hidden sm:block">{text}</span>
<ChevronRightIcon data-icon="inline-end" />
</PaginationLink>
);
}
function PaginationEllipsis({
className,
...props
}: React.ComponentProps<"span">) {
return (
<span
aria-hidden
className={cn(
"flex size-8 items-center justify-center [&_svg:not([class*='size-'])]:size-4",
className
)}
data-slot="pagination-ellipsis"
{...props}
>
<MoreHorizontalIcon />
<span className="sr-only">More pages</span>
</span>
);
}
export {
Pagination,
PaginationContent,
PaginationEllipsis,
PaginationItem,
PaginationLink,
PaginationNext,
PaginationPrevious,
};Update the import paths to match your project setup.
Usage
import {
Pagination,
PaginationContent,
PaginationItem,
PaginationLink,
PaginationNext,
PaginationPrevious,
} from "@/components/ui/pagination";<Pagination>
<PaginationContent>
<PaginationItem>
<PaginationPrevious href="#" />
</PaginationItem>
<PaginationItem>
<PaginationLink href="#">1</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationNext href="#" />
</PaginationItem>
</PaginationContent>
</Pagination>Examples
Simple
Show every page number without an ellipsis.
import {
Pagination,
PaginationContent,
PaginationItem,
PaginationLink,
} from "@/components/ui/pagination";
export function PaginationSimple() {
return (
<Pagination>
<PaginationContent>
<PaginationItem>
<PaginationLink href="#">1</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationLink href="#" isActive>
2
</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationLink href="#">3</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationLink href="#">4</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationLink href="#">5</PaginationLink>
</PaginationItem>
</PaginationContent>
</Pagination>
);
}Icons only
Pair with a Select for page size, keeping the controls minimal.
import { Field, FieldLabel } from "@/components/ui/field";
import {
Pagination,
PaginationContent,
PaginationItem,
PaginationNext,
PaginationPrevious,
} from "@/components/ui/pagination";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
export function PaginationIconsOnly() {
return (
<div className="flex items-center justify-between gap-4">
<Field className="w-fit" orientation="horizontal">
<FieldLabel htmlFor="select-rows-per-page">Rows per page</FieldLabel>
<Select defaultValue="25">
<SelectTrigger className="w-20" id="select-rows-per-page">
<SelectValue />
</SelectTrigger>
<SelectContent align="start">
<SelectItem value="10">10</SelectItem>
<SelectItem value="25">25</SelectItem>
<SelectItem value="50">50</SelectItem>
<SelectItem value="100">100</SelectItem>
</SelectContent>
</Select>
</Field>
<Pagination className="mx-0 w-auto">
<PaginationContent>
<PaginationItem>
<PaginationPrevious href="#" />
</PaginationItem>
<PaginationItem>
<PaginationNext href="#" />
</PaginationItem>
</PaginationContent>
</Pagination>
</div>
);
}Composition
Pagination
└── PaginationContent
├── PaginationItem
├── PaginationPrevious
├── PaginationNext
└── PaginationEllipsisIn Context
Table footer
import {
Pagination,
PaginationContent,
PaginationItem,
PaginationLink,
PaginationNext,
PaginationPrevious,
} from "@/components/ui/pagination";
export function PaginationTableFooter() {
return (
<Pagination>
<PaginationContent>
<PaginationItem>
<PaginationPrevious href="?page=1" />
</PaginationItem>
<PaginationItem>
<PaginationLink href="?page=1">1</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationLink href="?page=2" isActive>
2
</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationLink href="?page=3">3</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationNext href="?page=3" />
</PaginationItem>
</PaginationContent>
</Pagination>
);
}API Reference
PaginationLink
| Prop | Type | Default | Description |
|---|---|---|---|
href | string | — | Destination URL. |
isActive | boolean | — | Mark the link as the current page; sets aria-current. |
size | smdefaultlgicon | — | Button size. |
Other parts
All other parts extend React.ComponentProps<"div"> (or <a> for PaginationLink and PaginationPrevious / PaginationNext).
Accessibility
- Uses
<nav>witharia-label="pagination"for landmark navigation. - Active page sets
aria-current="page". - Previous and Next set
aria-label="Go to previous page"andaria-label="Go to next page".
Best Practices
- Hide when total is one page. Pagination with a single page is noise.
- Show first, last, current, and neighbors. Skip the middle with an ellipsis.
- Keep page size in the URL. Deep links and back button should work.
- Use pagination, not infinite scroll, for tables. Users need to jump around.