Pagination

The Pagination component allows users to navigate through multiple pages of content with an accessible and customizable interface. It’s perfect for tables, search results, and any content that spans multiple pages.

Usage

<script>
  import { 
    Pagination,
    PaginationContent,
    PaginationItem,
    PaginationLink,
    PaginationPrevButton,
    PaginationNextButton,
    PaginationEllipsis
  } from "$lib/components/ui/pagination";
  
  let currentPage = 1;
</script>

<Pagination bind:page={currentPage} count={100} perPage={10}>
  <PaginationContent>
    <PaginationItem>
      <PaginationPrevButton />
    </PaginationItem>
    <PaginationItem>
      <PaginationLink page={{ value: 1 }} />
    </PaginationItem>
    <PaginationItem>
      <PaginationEllipsis />
    </PaginationItem>
    <PaginationItem>
      <PaginationLink page={{ value: 10 }} />
    </PaginationItem>
    <PaginationItem>
      <PaginationNextButton />
    </PaginationItem>
  </PaginationContent>
</Pagination>

Examples

Basic Pagination

A simple pagination component with page numbers and navigation buttons.

With Ellipsis

A pagination component with ellipsis for large page counts.

Compact

A more compact pagination component with fewer visible pages.

Custom Navigation Buttons

A pagination component with customized navigation buttons.

With Content Info

A pagination component with information about the current page and total items.

Showing 11 to 20 of 45 results

Auto Generated Pages

A pagination component that generates page links automatically based on the current page and total pages.

API Reference

Pagination Components

ComponentDescription
PaginationThe root component that manages pagination state.
PaginationContentThe container for pagination items.
PaginationItemA wrapper for pagination links, buttons, or ellipsis.
PaginationLinkA link to a specific page.
PaginationPrevButtonA button to navigate to the previous page.
PaginationNextButtonA button to navigate to the next page.
PaginationEllipsisAn indicator for omitted pages.

Pagination Properties

PropertyTypeDefaultDescription
pagenumber1The current active page.
countnumber0The total number of items.
perPagenumber10The number of items per page.
siblingCountnumber1The number of siblings to show on each side of the current page when using auto-generation.
classstringundefinedCustom CSS classes.
onPageChangefunctionundefinedCallback fired when the page changes.

PaginationLink Properties

PropertyTypeDefaultDescription
page{ value: number }RequiredThe page object with its value.
isActivebooleanfalseWhether the link is for the current active page.
size"default" \| "sm" \| "lg" \| "icon""icon"The size of the link button.
classstringundefinedCustom CSS classes.

PaginationPrevButton/PaginationNextButton Properties

PropertyTypeDefaultDescription
classstringundefinedCustom CSS classes.
disabledbooleanfalseWhether the button is disabled (auto-disabled when on first/last page).
childrenfunctionDefault iconCustom content for the button.

Implementation

The Pagination component is built on top of bits-ui primitives. It leverages button variants for styling and integrates with Lucide icons for navigation buttons and ellipsis. Here’s a look at how some components are implemented:

<!-- Pagination root styling -->
<PaginationPrimitive.Root
  class={cn("mx-auto flex w-full flex-col items-center")}
  {count}
  {perPage}
  {siblingCount}
  bind:page
/>

<!-- PaginationContent styling -->
<ul class={cn("flex flex-row items-center gap-1")}>
  {@render children?.()}
</ul>

<!-- PaginationLink styling (using button variants) -->
<PaginationPrimitive.Page
  {page}
  class={cn(
    buttonVariants({
      variant: isActive ? "outline" : "ghost",
      size,
    })
  )}
/>

The component also provides automatic page generation through the createPagination helper function from bits-ui, which generates an array of page objects with appropriate ellipsis indicators based on the current page, total pages, and desired sibling count.