Pagination

React Pagination components are used to navigate through large sets of content split across multiple pages. They are commonly used in tables, search results, and content listings.

This Pagination component is built with React and styled using Tailwind CSS. It supports different layouts for page buttons, previous and next controls, and automatic ellipsis handling.

pagination

Installation

Install the component using the Tailgrids CLI.

npx @tailgrids/cli@latest add pagination

Usage

Import the component and control the active page using state.

import { Pagination } from "@/components/tailgrids/pagination";

const PaginationExample = () => (
  <Pagination
    currentPage={2}
    totalPages={10}
    onPageChange={p => console.log(p)}
  />
);

export default PaginationExample;

Composition

Pagination is also a set of composable parts, following the shadcn React Aria structure. Pass children instead of totalPages to build link-based pagination.

import {
  Pagination,
  PaginationContent,
  PaginationEllipsis,
  PaginationItem,
  PaginationLink,
  PaginationNext,
  PaginationPrevious
} from "@/components/tailgrids/pagination";

export const PaginationComposed = () => (
  <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>
        <PaginationEllipsis />
      </PaginationItem>
      <PaginationItem>
        <PaginationNext href="?page=3" />
      </PaginationItem>
    </PaginationContent>
  </Pagination>
);

Examples

Compact Variant

Use the compact variant for a minimal style, often suited for smaller sections or footers.

pagination

Full Side Layout

This is the default layout, showing both the icon and the text label ("Previous"/"Next") for side buttons.

pagination

Label-Only Side Layout

Shows only the text label ("Previous"/"Next") on desktop, but hides it on mobile to save space.

pagination

Icon-Only Side Layout

Uses icons only for previous and next buttons.

pagination

Mobile Preview

The pagination component is fully responsive, seamlessly adapting its layout and controls to ensure a consistent experience across various devices and screen sizes.

Page 1 of 10

API Reference

Pagination

PropTypeDefaultDescription
currentPagenumber-The currently active page number (1-based index).
totalPagesnumber-The total number of available pages.
onPageChange(page: number) => void-Callback function triggered when a page button is clicked.
variant'default' | 'compact''default'Overall pagination style.
sideLayout'full' | 'label' | 'icon''full'Controls the appearance of the "Previous" and "Next" buttons.

Composition parts

PartDescription
PaginationContentThe ul that holds the items.
PaginationItemAn li wrapping one link or ellipsis.
PaginationLinkA page link (React Aria Link). Set isActive for the current page.
PaginationPageA page button used by convenience mode (sets aria-current="page").
PaginationPreviousLink to the previous page.
PaginationNextLink to the next page.
PaginationEllipsisMarks skipped pages.

currentPage, totalPages, onPageChange, variant and sideLayout are Tailgrids-only conveniences on Pagination; they are ignored when you compose the parts yourself.

PaginationPage

PropTypeDefaultDescription
pagenumber-Required. Page number displayed on the button
isActiveboolean-Required. Marks the page as currently active
onPageChange(page: number) => void-Handler called with page when clicked
variant'default' | 'compact''default'Visual button style

Accessibility

  • Uses semantic <nav> with role="navigation" and aria-label="Pagination".
  • All interactive page buttons and side buttons have descriptive aria-label attributes.
  • The currently active page is indicated using aria-current="page".
  • Disabled states on side buttons clearly communicate when no previous or next page is available.