---
title: Pagination for Astro
description: "Native Astro page links with current-page and previous/next styles."
seo:
    title: Pagination for Astro | Shadcn & Tailwind CSS
related:
    - /components/table
    - /components/button
sidebar:
    label: "Pagination"
---

```astro
---
import {
  Pagination,
  PaginationContent,
  PaginationItem,
  PaginationLink,
  PaginationPrevious,
  PaginationNext,
  PaginationEllipsis,
} from "@/components/ui/pagination"
---

<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>
      <PaginationEllipsis />
    </PaginationItem>
    <PaginationItem>
      <PaginationNext href="?page=3" />
    </PaginationItem>
  </PaginationContent>
</Pagination>
```

## Installation

### Command

```sh
bunx --bun shadcn@latest add @gnostic/pagination
```

### Manual

Complete the [Installation guide](/docs/installation) first. Then copy the component files below.

No extra packages are required.

#### src/components/ui/pagination/pagination-content.astro

```astro
---
import type { HTMLAttributes } from "astro/types"
import { cn } from "cn"
type Props = HTMLAttributes<"ul">
const { class: className, ...props } = Astro.props
---

<ul
  data-slot="pagination-content"
  class={cn("flex flex-row items-center gap-1", className)}
  {...props}
>
  <slot />
</ul>
```

#### src/components/ui/pagination/pagination-link.astro

```astro
---
import type { HTMLAttributes } from "astro/types"
import { cn } from "cn"
import { buttonVariants, type ButtonVariantProps } from "@/components/ui/button"
type Props = HTMLAttributes<"a"> & {
  isActive?: boolean
  size?: ButtonVariantProps["size"]
}
const {
  class: className,
  isActive = false,
  size = "icon",
  ...props
} = Astro.props
---

<a
  data-slot="pagination-link"
  data-size={size}
  data-variant={isActive ? "outline" : "ghost"}
  data-active={isActive ? "" : undefined}
  aria-current={isActive ? "page" : undefined}
  class={cn(
    buttonVariants({ size, variant: isActive ? "outline" : "ghost" }),
    className,
  )}
  {...props}
>
  <slot />
</a>
```

#### src/components/ui/pagination/pagination-item.astro

```astro
---
import type { HTMLAttributes } from "astro/types"
type Props = HTMLAttributes<"li">
---

<li data-slot="pagination-item" {...Astro.props}>
  <slot />
</li>
```

#### src/components/ui/pagination/index.ts

```ts
export { default as Pagination } from './pagination.astro'
export { default as PaginationContent } from './pagination-content.astro'
export { default as PaginationItem } from './pagination-item.astro'
export { default as PaginationLink } from './pagination-link.astro'
export { default as PaginationPrevious } from './pagination-previous.astro'
export { default as PaginationNext } from './pagination-next.astro'
export { default as PaginationEllipsis } from './pagination-ellipsis.astro'
```

#### src/components/ui/pagination/pagination.astro

```astro
---
import type { HTMLAttributes } from "astro/types"
import { cn } from "cn"
type Props = HTMLAttributes<"nav">
const { class: className, ...props } = Astro.props
---

<nav
  data-slot="pagination"
  class={cn("mx-auto flex w-full justify-center", className)}
  aria-label="Pagination"
  {...props}
>
  <slot />
</nav>
```

#### src/components/ui/pagination/pagination-previous.astro

```astro
---
import type { ComponentProps } from "astro/types"
import { cn } from "cn"
import Icon from "@lucide/astro/icons/chevron-left"
import PaginationLink from "./pagination-link.astro"
type Props = ComponentProps<typeof PaginationLink>
const { class: className, ...props } = Astro.props
---

<PaginationLink
  aria-label="Previous page"
  size="default"
  class={cn("max-sm:aspect-square max-sm:p-0", className)}
  {...props}
>
  <Icon aria-hidden="true" />
  <span class="max-sm:hidden">
    <slot>Previous</slot>
  </span>
</PaginationLink>
```

#### src/components/ui/pagination/pagination-ellipsis.astro

```astro
---
import type { HTMLAttributes } from "astro/types"
import { cn } from "cn"
import MoreHorizontal from "@lucide/astro/icons/ellipsis"
type Props = HTMLAttributes<"span">
const { class: className, ...props } = Astro.props
---

<span
  data-slot="pagination-ellipsis"
  aria-hidden="true"
  class={cn("flex min-w-7 justify-center", className)}
  {...props}
>
  <MoreHorizontal class="size-5 sm:size-4" />
</span>
```

#### src/components/ui/pagination/pagination-next.astro

```astro
---
import type { ComponentProps } from "astro/types"
import { cn } from "cn"
import Icon from "@lucide/astro/icons/chevron-right"
import PaginationLink from "./pagination-link.astro"
type Props = ComponentProps<typeof PaginationLink>
const { class: className, ...props } = Astro.props
---

<PaginationLink
  aria-label="Next page"
  size="default"
  class={cn("max-sm:aspect-square max-sm:p-0", className)}
  {...props}
>
  <span class="max-sm:hidden">
    <slot>Next</slot>
  </span>
  <Icon aria-hidden="true" />
</PaginationLink>
```

Component classes use the preset configured during project setup. Select the same preset in the docs before copying Manual source. To change installed component classes, edit or reinstall their source. See [Theming](/docs/theming) for details.


## Usage

```ts
import { Pagination } from "@/components/ui/pagination"
```

Use the Code tab above for the complete Astro composition.

## API reference

Read the [registry source](/ui/r/pagination.json) for the exported parts and prop types.

## When to use Pagination

Build Pagination from a list of PaginationItem parts and real links. Calculate hrefs and the current page in your route or data layer. Set `isActive` on the current PaginationLink so it receives `aria-current="page"`.

## Keyboard and behavior

Navigation stays native and works without a client controller. Omit unavailable previous or next links, or render noninteractive text; an anchor has no native disabled attribute. Keep a useful label when more than one pagination region exists.

## Theme and layout

Number links use Button sizing and surface tokens. Previous and next text can hide at small widths while accessible names remain. Ellipsis is a visual gap, not a control that loads more pages.
