Theme
Customize appearance
Components
Pagination
Move between pages of a larger collection.
View component source ↗Preview
A minimal example to get started.
Installation
Install this component and its dependencies in a project initialized with shadcn.
pnpm dlx shadcn@latest add https://ui.hyunjoon.net/r/pagination.jsonUsage
This is the basic example. Use the Code tab above for the selected example. Adjust import aliases to match your project.
import { useState } from "react";
import {
Pagination,
PaginationContent,
PaginationItem,
PaginationLink,
PaginationPrevious,
PaginationNext,
} from "@/components/ui/pagination";
export default function Example() {
const [page, setPage] = useState(1);
return (
<Pagination>
<PaginationContent>
<PaginationItem>
<PaginationPrevious
href="#preview"
aria-disabled={page === 1}
onClick={(event) => {
event.preventDefault();
setPage((current) => Math.max(1, current - 1));
}}
/>
</PaginationItem>
{[1, 2, 3].map((number) => (
<PaginationItem key={number}>
<PaginationLink
href="#preview"
isActive={page === number}
onClick={(event) => {
event.preventDefault();
setPage(number);
}}
>
{number}
</PaginationLink>
</PaginationItem>
))}
<PaginationItem>
<PaginationNext
href="#preview"
aria-disabled={page === 3}
onClick={(event) => {
event.preventDefault();
setPage((current) => Math.min(3, current + 1));
}}
/>
</PaginationItem>
</PaginationContent>
</Pagination>
);
}
API reference
Derived from the installed component types. Native DOM props are also supported where applicable. A dash means no explicit default is documented. Some props depend on the selected mode.
Pagination
| Prop | Type | Default | Description |
|---|---|---|---|
ref | React.Ref<HTMLElement> | undefinedReact.Ref<HTMLElement> | undefined | — | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). |
defaultChecked | boolean | undefinedboolean | undefined | — | Initial checked state for an uncontrolled control. |
defaultValue | string | number | readonly string[] | undefinedstring | number | readonly string[] | undefined | — | Initial value for an uncontrolled component. |
className | string | undefinedstring | undefined | — | Additional CSS classes merged with the component styles. |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
onFocus | React.FocusEventHandler<HTMLElement> | undefinedReact.FocusEventHandler<HTMLElement> | undefined | — | Called when the control receives focus. |
onBlur | React.FocusEventHandler<HTMLElement> | undefinedReact.FocusEventHandler<HTMLElement> | undefined | — | Called when the control loses focus. |
onChange | React.ChangeEventHandler<HTMLElement, Element> | undefinedReact.ChangeEventHandler<HTMLElement, Element> | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | React.KeyboardEventHandler<HTMLElement> | undefinedReact.KeyboardEventHandler<HTMLElement> | undefined | — | Called when a key is pressed while this element is focused. |
onClick | React.MouseEventHandler<HTMLElement> | undefinedReact.MouseEventHandler<HTMLElement> | undefined | — | Called when the element is activated. |
PaginationContent
| Prop | Type | Default | Description |
|---|---|---|---|
ref | React.Ref<HTMLUListElement> | undefinedReact.Ref<HTMLUListElement> | undefined | — | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). |
defaultChecked | boolean | undefinedboolean | undefined | — | Initial checked state for an uncontrolled control. |
defaultValue | string | number | readonly string[] | undefinedstring | number | readonly string[] | undefined | — | Initial value for an uncontrolled component. |
className | string | undefinedstring | undefined | — | Additional CSS classes merged with the component styles. |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
onFocus | React.FocusEventHandler<HTMLUListElement> | undefinedReact.FocusEventHandler<HTMLUListElement> | undefined | — | Called when the control receives focus. |
onBlur | React.FocusEventHandler<HTMLUListElement> | undefinedReact.FocusEventHandler<HTMLUListElement> | undefined | — | Called when the control loses focus. |
onChange | React.ChangeEventHandler<HTMLUListElement, Element> | undefinedReact.ChangeEventHandler<HTMLUListElement, Element> | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | React.KeyboardEventHandler<HTMLUListElement> | undefinedReact.KeyboardEventHandler<HTMLUListElement> | undefined | — | Called when a key is pressed while this element is focused. |
onClick | React.MouseEventHandler<HTMLUListElement> | undefinedReact.MouseEventHandler<HTMLUListElement> | undefined | — | Called when the element is activated. |
PaginationEllipsis
| Prop | Type | Default | Description |
|---|---|---|---|
ref | React.Ref<HTMLSpanElement> | undefinedReact.Ref<HTMLSpanElement> | undefined | — | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). |
defaultChecked | boolean | undefinedboolean | undefined | — | Initial checked state for an uncontrolled control. |
defaultValue | string | number | readonly string[] | undefinedstring | number | readonly string[] | undefined | — | Initial value for an uncontrolled component. |
className | string | undefinedstring | undefined | — | Additional CSS classes merged with the component styles. |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
onFocus | React.FocusEventHandler<HTMLSpanElement> | undefinedReact.FocusEventHandler<HTMLSpanElement> | undefined | — | Called when the control receives focus. |
onBlur | React.FocusEventHandler<HTMLSpanElement> | undefinedReact.FocusEventHandler<HTMLSpanElement> | undefined | — | Called when the control loses focus. |
onChange | React.ChangeEventHandler<HTMLSpanElement, Element> | undefinedReact.ChangeEventHandler<HTMLSpanElement, Element> | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | React.KeyboardEventHandler<HTMLSpanElement> | undefinedReact.KeyboardEventHandler<HTMLSpanElement> | undefined | — | Called when a key is pressed while this element is focused. |
onClick | React.MouseEventHandler<HTMLSpanElement> | undefinedReact.MouseEventHandler<HTMLSpanElement> | undefined | — | Called when the element is activated. |
PaginationItem
| Prop | Type | Default | Description |
|---|---|---|---|
ref | React.Ref<HTMLLIElement> | undefinedReact.Ref<HTMLLIElement> | undefined | — | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). |
value | string | number | readonly string[] | undefinedstring | number | readonly string[] | undefined | — | The current value when controlled by the application. |
defaultChecked | boolean | undefinedboolean | undefined | — | Initial checked state for an uncontrolled control. |
defaultValue | string | number | readonly string[] | undefinedstring | number | readonly string[] | undefined | — | Initial value for an uncontrolled component. |
className | string | undefinedstring | undefined | — | Additional CSS classes merged with the component styles. |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
onFocus | React.FocusEventHandler<HTMLLIElement> | undefinedReact.FocusEventHandler<HTMLLIElement> | undefined | — | Called when the control receives focus. |
onBlur | React.FocusEventHandler<HTMLLIElement> | undefinedReact.FocusEventHandler<HTMLLIElement> | undefined | — | Called when the control loses focus. |
onChange | React.ChangeEventHandler<HTMLLIElement, Element> | undefinedReact.ChangeEventHandler<HTMLLIElement, Element> | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | React.KeyboardEventHandler<HTMLLIElement> | undefinedReact.KeyboardEventHandler<HTMLLIElement> | undefined | — | Called when a key is pressed while this element is focused. |
onClick | React.MouseEventHandler<HTMLLIElement> | undefinedReact.MouseEventHandler<HTMLLIElement> | undefined | — | Called when the element is activated. |
PaginationLink
| Prop | Type | Default | Description |
|---|---|---|---|
isActive | boolean | undefinedboolean | undefined | — | Marks this item as the current page or selection. |
size | "default" | "xs" | "sm" | "lg" | "icon" | "icon-xs" | "icon-sm" | "icon-lg" | null | undef…"default" | "xs" | "sm" | "lg" | "icon" | "icon-xs" | "icon-sm" | "icon-lg" | null | undefined | "icon" | Visual size of the component. |
ref | React.Ref<HTMLAnchorElement> | undefinedReact.Ref<HTMLAnchorElement> | undefined | — | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). |
href | string | undefinedstring | undefined | — | Destination URL for the link. |
target | React.HTMLAttributeAnchorTarget | undefinedReact.HTMLAttributeAnchorTarget | undefined | — | Browsing context in which the link opens. |
type | string | undefinedstring | undefined | — | The native input or button behavior. |
defaultChecked | boolean | undefinedboolean | undefined | — | Initial checked state for an uncontrolled control. |
defaultValue | string | number | readonly string[] | undefinedstring | number | readonly string[] | undefined | — | Initial value for an uncontrolled component. |
className | string | undefinedstring | undefined | — | Additional CSS classes merged with the component styles. |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
onFocus | React.FocusEventHandler<HTMLAnchorElement> | undefinedReact.FocusEventHandler<HTMLAnchorElement> | undefined | — | Called when the control receives focus. |
onBlur | React.FocusEventHandler<HTMLAnchorElement> | undefinedReact.FocusEventHandler<HTMLAnchorElement> | undefined | — | Called when the control loses focus. |
onChange | React.ChangeEventHandler<HTMLAnchorElement, Element> | undefinedReact.ChangeEventHandler<HTMLAnchorElement, Element> | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | React.KeyboardEventHandler<HTMLAnchorElement> | undefinedReact.KeyboardEventHandler<HTMLAnchorElement> | undefined | — | Called when a key is pressed while this element is focused. |
onClick | React.MouseEventHandler<HTMLAnchorElement> | undefinedReact.MouseEventHandler<HTMLAnchorElement> | undefined | — | Called when the element is activated. |
PaginationNext
| Prop | Type | Default | Description |
|---|---|---|---|
isActive | boolean | undefinedboolean | undefined | — | Marks this item as the current page or selection. |
size | "default" | "xs" | "sm" | "lg" | "icon" | "icon-xs" | "icon-sm" | "icon-lg" | null | undef…"default" | "xs" | "sm" | "lg" | "icon" | "icon-xs" | "icon-sm" | "icon-lg" | null | undefined | — | Visual size of the component. |
ref | React.Ref<HTMLAnchorElement> | undefinedReact.Ref<HTMLAnchorElement> | undefined | — | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). |
href | string | undefinedstring | undefined | — | Destination URL for the link. |
target | React.HTMLAttributeAnchorTarget | undefinedReact.HTMLAttributeAnchorTarget | undefined | — | Browsing context in which the link opens. |
type | string | undefinedstring | undefined | — | The native input or button behavior. |
defaultChecked | boolean | undefinedboolean | undefined | — | Initial checked state for an uncontrolled control. |
defaultValue | string | number | readonly string[] | undefinedstring | number | readonly string[] | undefined | — | Initial value for an uncontrolled component. |
className | string | undefinedstring | undefined | — | Additional CSS classes merged with the component styles. |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
onFocus | React.FocusEventHandler<HTMLAnchorElement> | undefinedReact.FocusEventHandler<HTMLAnchorElement> | undefined | — | Called when the control receives focus. |
onBlur | React.FocusEventHandler<HTMLAnchorElement> | undefinedReact.FocusEventHandler<HTMLAnchorElement> | undefined | — | Called when the control loses focus. |
onChange | React.ChangeEventHandler<HTMLAnchorElement, Element> | undefinedReact.ChangeEventHandler<HTMLAnchorElement, Element> | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | React.KeyboardEventHandler<HTMLAnchorElement> | undefinedReact.KeyboardEventHandler<HTMLAnchorElement> | undefined | — | Called when a key is pressed while this element is focused. |
onClick | React.MouseEventHandler<HTMLAnchorElement> | undefinedReact.MouseEventHandler<HTMLAnchorElement> | undefined | — | Called when the element is activated. |
text | string | undefinedstring | undefined | "Next" | Text displayed by the component. |
PaginationPrevious
| Prop | Type | Default | Description |
|---|---|---|---|
isActive | boolean | undefinedboolean | undefined | — | Marks this item as the current page or selection. |
size | "default" | "xs" | "sm" | "lg" | "icon" | "icon-xs" | "icon-sm" | "icon-lg" | null | undef…"default" | "xs" | "sm" | "lg" | "icon" | "icon-xs" | "icon-sm" | "icon-lg" | null | undefined | — | Visual size of the component. |
ref | React.Ref<HTMLAnchorElement> | undefinedReact.Ref<HTMLAnchorElement> | undefined | — | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). |
href | string | undefinedstring | undefined | — | Destination URL for the link. |
target | React.HTMLAttributeAnchorTarget | undefinedReact.HTMLAttributeAnchorTarget | undefined | — | Browsing context in which the link opens. |
type | string | undefinedstring | undefined | — | The native input or button behavior. |
defaultChecked | boolean | undefinedboolean | undefined | — | Initial checked state for an uncontrolled control. |
defaultValue | string | number | readonly string[] | undefinedstring | number | readonly string[] | undefined | — | Initial value for an uncontrolled component. |
className | string | undefinedstring | undefined | — | Additional CSS classes merged with the component styles. |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
onFocus | React.FocusEventHandler<HTMLAnchorElement> | undefinedReact.FocusEventHandler<HTMLAnchorElement> | undefined | — | Called when the control receives focus. |
onBlur | React.FocusEventHandler<HTMLAnchorElement> | undefinedReact.FocusEventHandler<HTMLAnchorElement> | undefined | — | Called when the control loses focus. |
onChange | React.ChangeEventHandler<HTMLAnchorElement, Element> | undefinedReact.ChangeEventHandler<HTMLAnchorElement, Element> | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | React.KeyboardEventHandler<HTMLAnchorElement> | undefinedReact.KeyboardEventHandler<HTMLAnchorElement> | undefined | — | Called when a key is pressed while this element is focused. |
onClick | React.MouseEventHandler<HTMLAnchorElement> | undefinedReact.MouseEventHandler<HTMLAnchorElement> | undefined | — | Called when the element is activated. |
text | string | undefinedstring | undefined | "Previous" | Text displayed by the component. |
Usage notes
Track the current page and mark its link active. Connect previous and next actions to your data source or route.