# Pagination

- **[Atoms](/components/)**

Page navigation with Previous, Next and numbered pages, as buttons or as plain links.

## When to use

- **Use for**: A list split over pages, with the current page and a way to move.
- **Not for**: Endless feeds, or fewer than two pages (render nothing).
- **Pairs with**: Table, lists, Cards.

## Preview

pagination.tsx

```
import { Theme } from '@/components/klarhimmel/theme/style';
import { Pagination } from '@/components/klarhimmel/ui/pagination';

export default function Example() {
  return (
    <Theme theme="brand">
      // links work without script: each page is its own address
      <Pagination page={3} pageCount={12} href={(n) => `/rooms?page=${n}`} />
    </Theme>
  );
}
```

## Import

- **CLI**

  ```
  npx shadcn add @klarhimmel/pagination
  ```
- **Import**

  ```
  import { Pagination, pageRange } from '@/components/klarhimmel/ui/pagination';
  ```

- **Files**: pagination.tsx, in components/klarhimmel/ui/. With it: button, theme, utils. npm: lucide-react.
- **Render in**: Render it inside <Theme>, once near the root of your app. Tokens and fonts are scoped to it, so outside it the component is unstyled.

## Examples

- **Links**

  ```
  import { Pagination } from '@/components/klarhimmel/ui/pagination';
  
  export default function PaginationLinks() {
    return (
      <div className="flex w-[min(40rem,calc(100cqw-3rem))] flex-col items-center gap-6">
        <Pagination page={1} pageCount={6} href={(n) => `/rooms?page=${n}`} label="Room pages" />
        <Pagination page={6} pageCount={6} href={(n) => `/rooms?page=${n}`} label="Last page" />
      </div>
    );
  }
  ```
- **Edges**

  ```
  import { Pagination } from '@/components/klarhimmel/ui/pagination';
  
  export default function PaginationEdges() {
    return (
      <div className="flex w-[min(40rem,calc(100cqw-3rem))] flex-col items-center gap-6">
        <Pagination page={2} pageCount={3} href={(n) => `?page=${n}`} label="Three pages" />
        <Pagination page={20} pageCount={40} href={(n) => `?page=${n}`} label="Forty pages" siblings={2} />
      </div>
    );
  }
  ```

## Props

- **page**: Rounded down and clamped to the available pages; non-finite values use page 1.
- **pageCount**: Rounded down with a minimum of 1; non-finite values use 1.
- **onPageChange**: Buttons mode: called with the new page.
- **href**: Links mode: the URL of a page. Use this when each page is its own address (it works without script).
- **siblings**: Whole, non-negative adjacent pages; non-finite values use the default of 1.
- **label**: Accessible name of the navigation landmark.
- **className**: Extra classes, merged after the component's own.

## Accessibility

- Tab · Moves through the page links or buttons
- Enter / Space · Goes to the page

[Accessibility](/get-started/accessibility)

The current page has aria-current="page". Previous and Next stay as disabled buttons at the ends. Use links when every page has its own address.

[Previous](/components/sidebar)

[Next](/components/label)
