On this page

Pagination

Live examples of Pagination, with the exact Vue file that renders each one.

Every example is a complete Vue file. Copy it into an app that has the registry installed, or open it in StackBlitz.

Page numbers

Ellipses stand for the pages in between.

PaginationDefault.vue
<script setup lang="ts">
import { ref } from 'vue'
import {
  Pagination,
  PaginationContent,
  PaginationEllipsis,
  PaginationItem,
  PaginationNext,
  PaginationPrevious,
} from '@/components/ui/pagination'

// 312 orders, 20 a page: 16 pages. reka-ui works out which page numbers to show.
const page = ref(4)
</script>

<template>
  <Pagination v-slot="{ page: current }" v-model:page="page" :total="312" :items-per-page="20" :sibling-count="1" show-edges aria-label="Order pages">
    <PaginationContent v-slot="{ items }">
      <PaginationPrevious />
      <template v-for="(item, index) in items" :key="index">
        <PaginationItem v-if="item.type === 'page'" :value="item.value" :is-active="item.value === current">
          {{ item.value }}
        </PaginationItem>
        <PaginationEllipsis v-else :index="index" />
      </template>
      <PaginationNext />
    </PaginationContent>
  </Pagination>
</template>

Under a table

The range shown and previous/next buttons, no page numbers.

Showing 21–40 of 312 orders

PaginationCompact.vue
<script setup lang="ts">
import { computed, ref } from 'vue'
import {
  Pagination,
  PaginationContent,
  PaginationFirst,
  PaginationLast,
  PaginationNext,
  PaginationPrevious,
} from '@/components/ui/pagination'

// Under a table: the range shown, and buttons to move. No page numbers.
const total = 312
const perPage = 20
const page = ref(2)
const first = computed(() => (page.value - 1) * perPage + 1)
const last = computed(() => Math.min(page.value * perPage, total))
</script>

<template>
  <div class="flex w-full flex-wrap items-center justify-between gap-(--bh-space-100)">
    <p class="m-0 text-(--bh-color-text-subtle) tabular-nums">
      Showing {{ first }}–{{ last }} of {{ total }} orders
    </p>
    <Pagination v-model:page="page" :total="total" :items-per-page="perPage" aria-label="Order pages" class="mx-0 w-auto">
      <PaginationContent>
        <PaginationFirst />
        <PaginationPrevious />
        <PaginationNext />
        <PaginationLast />
      </PaginationContent>
    </Pagination>
  </div>
</template>