Skip to content
Haze UI

Pagination

Previous and next controls with numbered page links and ellipsis gaps, and the current page drawn as a raised key.

pnpm dlx shadcn@latest add @haze/pagination
Open preview in a new tab
Liveno JavaScript

When to use

  • Search results, tables or blog archives split over server-rendered pages
  • Letting readers jump straight to a page number
  • A page list that must shrink to icon-only arrows on a 320 px screen

When not to use

  • Feeds that load more on scroll
  • Two or three steps in a wizard; use stepper

Installation

Add the Haze registry to components.json once, then install Pagination with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.

pnpm dlx shadcn@latest add @haze/pagination
First time? Registry and theme setup

1. Add to components.json:

{
  "registries": {
    "@haze": "http://localhost:4329/r/{name}.json"
  }
}

2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";

API reference

PropTypeDefaultDescription
current*number–Current page, 1-based; clamped to the range 1 to total.
total*number–Number of pages.
hrefPrefixstring"?page="Page n links to the prefix followed by n.
siblingsnumber1Pages shown on each side of the current page; the first and last page always show.
labelstring"Pagination"Accessible name of the nav landmark. Give each pagination on one page a different name.
previousLabelstring"Previous"Text of the previous control; below sm it is visually hidden but stays in the accessibility tree.
nextLabelstring"Next"Text of the next control; below sm it is visually hidden but stays in the accessibility tree.
pageLabelstring"Page"Prefix of each page link's accessible name, followed by the number ("Page 4"). Translate it with the other labels.
moreLabelstring"More pages"Screen-reader text for the "…" gaps.
classstring–Extra classes on the nav.

Keyboard interactions

Tab
Move between the page links
Enter
Open the focused page

Accessibility

  • The current page carries aria-current="page" and is drawn as a raised key with a border and a fill, so it is told apart without color alone.
  • On the first and last page the previous or next control is a span with aria-disabled, not a dead link.
  • Number links are named "Page 4" (the prefix is the pageLabel prop) and are 36 by 36 px. The "…" gaps are aria-hidden and carry hidden text from moreLabel.
  • The list has role="list" so Safari keeps its list semantics. With total below 1 nothing is rendered.
  • Two paginations on one page need different label values, so their landmarks can be told apart.

Notes for AI

Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.

  • Install and use

    Install the Haze UI component "Pagination" with `npx shadcn@latest add @haze/pagination`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import Pagination from "@/components/haze/ui/pagination.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/pagination.md

  • Customize with real content

    Adapt the Haze pagination ui for our product. Replace the demo values of these props with our real content: current, total, hrefPrefix, siblings, label, previousLabel, nextLabel, pageLabel, moreLabel, class. Keep the layout, the heading level rules and these accessibility details: The current page carries aria-current="page" and is drawn as a raised key with a border and a fill, so it is told apart without color alone. On the first and last page the previous or next control is a span with aria-disabled, not a dead link. Number links are named "Page 4" (the prefix is the pageLabel prop) and are 36 by 36 px. The "…" gaps are aria-hidden and carry hidden text from moreLabel. The list has role="list" so Safari keeps its list semantics. With total below 1 nothing is rendered. Two paginations on one page need different label values, so their landmarks can be told apart. Do not add raw color classes; use the Haze tokens.

  • Choose the right block

    Before using pagination, check it fits: use it when search results, tables or blog archives split over server-rendered pages; letting readers jump straight to a page number; a page list that must shrink to icon-only arrows on a 320 px screen. Avoid it when feeds that load more on scroll; two or three steps in a wizard; use stepper. Alternatives: @haze/stepper, @haze/breadcrumb.

Dependencies

  • npm: @lucide/astro
  • @haze/utils
  • @haze/theme (one-time setup)

Source · Original Haze UI work.

Catalog

↑↓ moveEnter openEsc close

Keyboard shortcuts

CtrlK
Command palette
/
Focus search
←↑→↓
Move between cards
jk
Next / previous card
ci
Copy code / install command (detail page)
[]
Previous / next entry
?
This help
Esc
Close dialog