# Pagination

- **Section:** Components
- **URL:** https://refast.fastapicloud.dev/docs/components/pagination
- **Markdown:** https://refast.fastapicloud.dev/docs/components/pagination.md
- **Source:** https://github.com/idling-mind/refast-docs/blob/main/docs/pages/components/navigation/pagination.py
- **Live examples:** the widgets on this page need a browser; open the URL above to try them.
- **Applies to:** refast 0.12.2

Navigate through pages of content with Previous/Next and numbered page links.

```python
from refast.components import (
    Pagination, PaginationContent, PaginationItem,
    PaginationLink, PaginationPrevious, PaginationNext, PaginationEllipsis,
)
```

```python
Pagination(
    children=[
        PaginationContent(
            children=[
                PaginationItem(children=[PaginationPrevious(on_click=ctx.callback(go_prev))]),
                PaginationItem(children=[PaginationLink("1", active=True, on_click=ctx.callback(go_page, page=1))]),
                PaginationItem(children=[PaginationLink("2", on_click=ctx.callback(go_page, page=2))]),
                PaginationItem(children=[PaginationEllipsis()]),
                PaginationItem(children=[PaginationNext(on_click=ctx.callback(go_next))]),
            ]
        )
    ]
)
```

## Props

### `PaginationLink`

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| `label` | `str` | *(required)* | Page label text |
| `href` | `str` | `"#"` | URL for the link |
| `active` | `bool` | `False` | Highlights the current page |
| `on_click` | `Callback \| None` | `None` | Server click callback |

### `PaginationPrevious` / `PaginationNext`

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| `href` | `str` | `"#"` | Navigation URL |
| `on_click` | `Callback \| None` | `None` | Server click callback |

## Component Hierarchy

```
Pagination
└── PaginationContent
    ├── PaginationItem
    │   └── PaginationPrevious
    ├── PaginationItem
    │   └── PaginationLink (active)
    ├── PaginationItem
    │   └── PaginationLink
    ├── PaginationItem
    │   └── PaginationEllipsis
    ├── PaginationItem
    │   └── PaginationLink
    └── PaginationItem
        └── PaginationNext
```

## Server-side Controlled Example

```python
async def go_prev(ctx: Context):
    page = ctx.state.get("page", 1)
    if page > 1:
        ctx.state.set("page", page - 1)
    await ctx.refresh()

async def go_next(ctx: Context):
    page = ctx.state.get("page", 1)
    total = ctx.state.get("total_pages", 10)
    if page < total:
        ctx.state.set("page", page + 1)
    await ctx.refresh()
```

---

Part of the Refast documentation: [all pages](https://refast.fastapicloud.dev/llms.txt), [everything on one page](https://refast.fastapicloud.dev/llms-full.txt), [search](https://refast.fastapicloud.dev/api/search?q=save_prop).
