Skip to content

ComponentsFeedback

SourceSource

Pagination

Numbered page buttons with previous/next controls, plus a divider-style load-more row.

Numbered page buttons with previous/next controls, plus a divider-style load-more row. Compose it from the exported registry parts so local content and behaviour stay in the application while the visual contract stays token-driven.

Root class newt-pagination
"use client"

import * as React from "react"

import { Button } from "@/registry/bases/newt/ui/button"
import {
  LoadMore,
  Pagination,
  PaginationButton,
} from "@/registry/bases/newt/ui/pagination"

const PAGES = [1, 2, 3]

export default function PaginationDemo() {
  const [page, setPage] = React.useState(1)

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <Pagination>
        <PaginationButton
          aria-label="Previous page"
          disabled={page === 1}
          onClick={() => setPage((p) => Math.max(1, p - 1))}
        >
          &lsaquo;
        </PaginationButton>
        {PAGES.map((n) => (
          <PaginationButton
            key={n}
            active={page === n}
            onClick={() => setPage(n)}
          >
            {n}
          </PaginationButton>
        ))}
        <PaginationButton
          aria-label="Next page"
          disabled={page === PAGES.length}
          onClick={() => setPage((p) => Math.min(PAGES.length, p + 1))}
        >
          &rsaquo;
        </PaginationButton>
      </Pagination>

      <LoadMore>
        <Button variant="secondary" size="sm">
          Load more
        </Button>
      </LoadMore>
    </div>
  )
}
<script setup lang="ts">
import { ref } from "vue"
import { Button } from "~~/registry/bases/newt/ui/button"
import {
  LoadMore,
  Pagination,
  PaginationButton,
} from "~~/registry/bases/newt/ui/pagination"

const pages = [1, 2, 3]
const page = ref(1)
</script>

<template>
  <div class="flex w-full max-w-sm flex-col gap-6">
    <Pagination>
      <PaginationButton
        aria-label="Previous page"
        :disabled="page === 1"
        @click="page = Math.max(1, page - 1)"
      >
        &lsaquo;
      </PaginationButton>
      <PaginationButton
        v-for="n in pages"
        :key="n"
        :active="page === n"
        @click="page = n"
      >
        {{ n }}
      </PaginationButton>
      <PaginationButton
        aria-label="Next page"
        :disabled="page === pages.length"
        @click="page = Math.min(pages.length, page + 1)"
      >
        &rsaquo;
      </PaginationButton>
    </Pagination>

    <LoadMore>
      <Button variant="secondary" size="sm">Load more</Button>
    </LoadMore>
  </div>
</template>

Installation

npx newtui@latest add paginationnpx shadcn@latest add @newtui/paginationnpx shadcn-vue@latest add @newtui/paginationpnpm dlx newtui@latest add paginationpnpm dlx shadcn@latest add @newtui/paginationpnpm dlx shadcn-vue@latest add @newtui/paginationyarn dlx newtui@latest add paginationyarn dlx shadcn@latest add @newtui/paginationyarn dlx shadcn-vue@latest add @newtui/paginationbunx newtui@latest add paginationbunx shadcn@latest add @newtui/paginationbunx shadcn-vue@latest add @newtui/paginationdeno run -A npm:newtui@latest add paginationdeno run -A npm:shadcn@latest add @newtui/paginationdeno run -A npm:shadcn-vue@latest add @newtui/paginationvlx newtui@latest add paginationvlx shadcn@latest add @newtui/paginationvlx shadcn-vue@latest add @newtui/paginationvp dlx newtui@latest add paginationvp dlx shadcn@latest add @newtui/paginationvp dlx shadcn-vue@latest add @newtui/paginationnubx newtui@latest add paginationnubx shadcn@latest add @newtui/paginationnubx shadcn-vue@latest add @newtui/paginationnlx newtui@latest add paginationnlx shadcn@latest add @newtui/paginationnlx shadcn-vue@latest add @newtui/paginationupx newtui@latest add paginationupx shadcn@latest add @newtui/paginationupx shadcn-vue@latest add @newtui/pagination

The shadcn CLI needs the @newtui registry in your components.json. Set it up.

Install the dependencies

npm install class-variance-authoritypnpm add class-variance-authorityyarn add class-variance-authoritybun add class-variance-authoritydeno add npm:class-variance-authorityvlt install class-variance-authorityvp add class-variance-authoritynub add class-variance-authorityni class-variance-authorityupm add class-variance-authority

Add the components it builds on

Copy the source into your project

import { cva, type VariantProps } from "class-variance-authority"
import * as React from "react"

import { cn } from "@/lib/utils"

const Pagination = React.forwardRef<HTMLElement, React.ComponentProps<"nav">>(
  ({ className, ...props }, ref) => (
    <nav
      ref={ref}
      role="navigation"
      aria-label="Pagination"
      className={cn("flex items-center gap-1", className)}
      {...props}
    />
  )
)
Pagination.displayName = "Pagination"

const paginationButtonVariants = cva(
  "flex h-8 min-w-8 cursor-pointer items-center justify-center rounded-[var(--newt-radius-sm)] border px-2 text-[13px] font-medium disabled:cursor-not-allowed disabled:opacity-40",
  {
    variants: {
      active: {
        false:
          "border-newt-border bg-newt-bg-elevated text-newt-text-secondary hover:bg-newt-bg-hover hover:text-newt-text-primary",
        true: "border-newt-brand bg-newt-brand text-newt-on-accent",
      },
    },
    defaultVariants: {
      active: false,
    },
  }
)

export interface PaginationButtonProps
  extends
    React.ButtonHTMLAttributes<HTMLButtonElement>,
    VariantProps<typeof paginationButtonVariants> {}

const PaginationButton = React.forwardRef<
  HTMLButtonElement,
  PaginationButtonProps
>(({ className, active, ...props }, ref) => (
  <button
    ref={ref}
    type="button"
    aria-current={active ? "page" : undefined}
    data-active={active ? "" : undefined}
    className={cn(paginationButtonVariants({ active }), className)}
    {...props}
  />
))
PaginationButton.displayName = "PaginationButton"

const PaginationEllipsis = React.forwardRef<
  HTMLSpanElement,
  React.ComponentProps<"span">
>(({ className, children, ...props }, ref) => (
  <span
    ref={ref}
    aria-hidden="true"
    className={cn("px-1 text-[13px] text-newt-text-muted", className)}
    {...props}
  >
    {children ?? "…"}
  </span>
))
PaginationEllipsis.displayName = "PaginationEllipsis"

/** A "load more" row: centred content flanked by hairline rules. */
const LoadMore = React.forwardRef<HTMLDivElement, React.ComponentProps<"div">>(
  ({ className, ...props }, ref) => (
    <div
      ref={ref}
      className={cn(
        "flex items-center justify-center gap-2.5 p-3 text-[13px] text-newt-text-muted before:h-px before:flex-1 before:bg-newt-border before:content-[''] after:h-px after:flex-1 after:bg-newt-border after:content-['']",
        className
      )}
      {...props}
    />
  )
)
LoadMore.displayName = "LoadMore"

export {
  Pagination,
  PaginationButton,
  PaginationEllipsis,
  LoadMore,
  paginationButtonVariants,
}
<script setup lang="ts">
import type { HTMLAttributes } from "vue"

import { cn } from "@/lib/utils"

const props = defineProps<{
  class?: HTMLAttributes["class"]
}>()
</script>

<template>
  <nav
    role="navigation"
    aria-label="Pagination"
    :class="cn('flex items-center gap-1', props.class)"
  >
    <slot />
  </nav>
</template>
<script setup lang="ts">
import type { ButtonHTMLAttributes, HTMLAttributes } from "vue"

import { cn } from "@/lib/utils"

import { paginationButtonVariants } from "."

const props = withDefaults(
  defineProps<{
    active?: boolean
    disabled?: ButtonHTMLAttributes["disabled"]
    class?: HTMLAttributes["class"]
  }>(),
  { active: false }
)
</script>

<template>
  <button
    type="button"
    :disabled="props.disabled"
    :aria-current="props.active ? 'page' : undefined"
    :data-active="props.active ? '' : undefined"
    :class="cn(paginationButtonVariants({ active: props.active }), props.class)"
  >
    <slot />
  </button>
</template>
<script setup lang="ts">
import type { HTMLAttributes } from "vue"

import { cn } from "@/lib/utils"

const props = defineProps<{
  class?: HTMLAttributes["class"]
}>()
</script>

<template>
  <span
    aria-hidden="true"
    :class="cn('px-1 text-[13px] text-newt-text-muted', props.class)"
  >
    <slot>&hellip;</slot>
  </span>
</template>
<script setup lang="ts">
import type { HTMLAttributes } from "vue"

import { cn } from "@/lib/utils"

const props = defineProps<{
  class?: HTMLAttributes["class"]
}>()
</script>

<template>
  <div
    :class="
      cn(
        'flex items-center justify-center gap-2.5 p-3 text-[13px] text-newt-text-muted before:h-px before:flex-1 before:bg-newt-border before:content-[\'\'] after:h-px after:flex-1 after:bg-newt-border after:content-[\'\']',
        props.class
      )
    "
  >
    <slot />
  </div>
</template>
import { cva, type VariantProps } from "class-variance-authority"

export { default as Pagination } from "./Pagination.vue"
export { default as PaginationButton } from "./PaginationButton.vue"
export { default as PaginationEllipsis } from "./PaginationEllipsis.vue"
export { default as LoadMore } from "./LoadMore.vue"

export const paginationButtonVariants = cva(
  "flex h-8 min-w-8 cursor-pointer items-center justify-center rounded-[var(--newt-radius-sm)] border px-2 text-[13px] font-medium disabled:cursor-not-allowed disabled:opacity-40",
  {
    variants: {
      active: {
        false:
          "border-newt-border bg-newt-bg-elevated text-newt-text-secondary hover:bg-newt-bg-hover hover:text-newt-text-primary",
        true: "border-newt-brand bg-newt-brand text-newt-on-accent",
      },
    },
    defaultVariants: {
      active: false,
    },
  }
)

export type PaginationButtonVariants = VariantProps<
  typeof paginationButtonVariants
>

Update the import paths

The files import @/lib/utils and sibling components through the aliases in your components.json. Point them at wherever those live in your project.

No CLI, no components.json: paste this into Claude, Cursor, Copilot or any coding assistant and it adds Pagination to your React project by hand. The prompt carries the source of every file the CLI would write — this component's and those of the components it builds on — with the imports already pointed at the default aliases.

No CLI, no components.json: paste this into Claude, Cursor, Copilot or any coding assistant and it adds Pagination to your Vue project by hand. The prompt carries the source of every file the CLI would write — this component's and those of the components it builds on — with the imports already pointed at the default aliases.

Usage

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

export function Example() {
  return <Pagination />
}
<script setup lang="ts">
import { Pagination, PaginationButton, PaginationEllipsis, LoadMore } from "@/components/ui/pagination"
</script>

<template>
  <Pagination />
</template>

Examples

With an ellipsis

When the pages do not fit in a row, show the first, the last, the current one and its neighbours, and put a PaginationEllipsis where pages are left out.

Root class newt-pagination
"use client"

import * as React from "react"

import {
  Pagination,
  PaginationButton,
  PaginationEllipsis,
} from "@/registry/bases/newt/ui/pagination"

const TOTAL = 12

/**
 * The first page, the last, the current one and its neighbours. An item
 * without a page is a gap.
 */
function pageItems(current: number): { key: string; page: number | null }[] {
  const start = Math.max(2, current - 1)
  const end = Math.min(TOTAL - 1, current + 1)
  const pages = [
    1,
    ...Array.from({ length: end - start + 1 }, (_, i) => start + i),
    TOTAL,
  ].map((page) => ({ key: String(page), page }))
  return [
    ...pages.slice(0, 1),
    ...(start > 2 ? [{ key: "before", page: null }] : []),
    ...pages.slice(1, -1),
    ...(end < TOTAL - 1 ? [{ key: "after", page: null }] : []),
    ...pages.slice(-1),
  ]
}

/*
 * Twelve pages do not fit in a row. `PaginationEllipsis` stands in for the
 * ones left out on either side of the current page.
 */
export default function PaginationEllipsisDemo() {
  const [page, setPage] = React.useState(6)

  return (
    <Pagination>
      <PaginationButton
        aria-label="Previous page"
        disabled={page === 1}
        onClick={() => setPage(page - 1)}
      >
        &lsaquo;
      </PaginationButton>
      {pageItems(page).map(({ key, page: target }) =>
        target === null ? (
          <PaginationEllipsis key={key} />
        ) : (
          <PaginationButton
            key={key}
            active={page === target}
            onClick={() => setPage(target)}
          >
            {target}
          </PaginationButton>
        )
      )}
      <PaginationButton
        aria-label="Next page"
        disabled={page === TOTAL}
        onClick={() => setPage(page + 1)}
      >
        &rsaquo;
      </PaginationButton>
    </Pagination>
  )
}
<script setup lang="ts">
import { computed, ref } from "vue"
import {
  Pagination,
  PaginationButton,
  PaginationEllipsis,
} from "~~/registry/bases/newt/ui/pagination"

/*
 * Twelve pages do not fit in a row. `PaginationEllipsis` stands in for the
 * ones left out on either side of the current page.
 */
const total = 12
const page = ref(6)

/**
 * The first page, the last, the current one and its neighbours. An item
 * without a page is a gap.
 */
const items = computed<{ key: string; page: number | null }[]>(() => {
  const start = Math.max(2, page.value - 1)
  const end = Math.min(total - 1, page.value + 1)
  const pages = [
    1,
    ...Array.from({ length: end - start + 1 }, (_, i) => start + i),
    total,
  ].map((n) => ({ key: String(n), page: n }))
  return [
    ...pages.slice(0, 1),
    ...(start > 2 ? [{ key: "before", page: null }] : []),
    ...pages.slice(1, -1),
    ...(end < total - 1 ? [{ key: "after", page: null }] : []),
    ...pages.slice(-1),
  ]
})
</script>

<template>
  <Pagination>
    <PaginationButton
      aria-label="Previous page"
      :disabled="page === 1"
      @click="page -= 1"
    >
      &lsaquo;
    </PaginationButton>
    <template v-for="item in items" :key="item.key">
      <PaginationEllipsis v-if="item.page === null" />
      <PaginationButton
        v-else
        :active="page === item.page"
        @click="page = item.page"
      >
        {{ item.page }}
      </PaginationButton>
    </template>
    <PaginationButton
      aria-label="Next page"
      :disabled="page === total"
      @click="page += 1"
    >
      &rsaquo;
    </PaginationButton>
  </Pagination>
</template>

Previous and next

When nobody needs to jump to a page, two labelled buttons and the position are enough. disabled stops each button at its end of the range.

Root class newt-pagination
"use client"

import * as React from "react"

import {
  Pagination,
  PaginationButton,
} from "@/registry/bases/newt/ui/pagination"

const TOTAL = 8

/*
 * When nobody needs to jump to a page, two labelled buttons and a position
 * are enough. Both buttons disable themselves at their end of the range.
 */
export default function PaginationPrevNextDemo() {
  const [page, setPage] = React.useState(1)

  return (
    <Pagination className="gap-3">
      <PaginationButton
        className="px-3"
        disabled={page === 1}
        onClick={() => setPage(page - 1)}
      >
        Previous
      </PaginationButton>
      <span aria-live="polite" className="text-[13px] text-newt-text-muted">
        Page {page} of {TOTAL}
      </span>
      <PaginationButton
        className="px-3"
        disabled={page === TOTAL}
        onClick={() => setPage(page + 1)}
      >
        Next
      </PaginationButton>
    </Pagination>
  )
}
<script setup lang="ts">
import { ref } from "vue"
import {
  Pagination,
  PaginationButton,
} from "~~/registry/bases/newt/ui/pagination"

/*
 * When nobody needs to jump to a page, two labelled buttons and a position
 * are enough. Both buttons disable themselves at their end of the range.
 */
const total = 8
const page = ref(1)
</script>

<template>
  <Pagination class="gap-3">
    <PaginationButton class="px-3" :disabled="page === 1" @click="page -= 1">
      Previous
    </PaginationButton>
    <span aria-live="polite" class="text-[13px] text-newt-text-muted">
      Page {{ page }} of {{ total }}
    </span>
    <PaginationButton
      class="px-3"
      :disabled="page === total"
      @click="page += 1"
    >
      Next
    </PaginationButton>
  </Pagination>
</template>

Load more

LoadMore is a row between two rules, not a button. Give it the control while there is more to fetch, and a closing line once the list has reached its end.

Root class newt-pagination
"use client"

import * as React from "react"

import { Button } from "@/registry/bases/newt/ui/button"
import { LoadMore } from "@/registry/bases/newt/ui/pagination"

const ENTRIES = [
  "Ada changed the server name",
  "Lin created #announcements",
  "Ada gave Sol the Moderator role",
  "Sol deleted 4 messages in #lounge",
  "Lin updated the welcome screen",
  "Sol timed out a member for 10 minutes",
  "Ada created an invite that never expires",
  "Lin renamed #general to #lobby",
]
const STEP = 3

/*
 * `LoadMore` is a row, not a button: it holds the control while there is more
 * to fetch, and the closing line once the list has reached its end.
 */
export default function PaginationLoadMoreDemo() {
  const [shown, setShown] = React.useState(STEP)

  return (
    <div className="flex w-full max-w-sm flex-col">
      <ul className="flex flex-col gap-2 text-sm text-newt-text-secondary">
        {ENTRIES.slice(0, shown).map((entry) => (
          <li key={entry}>{entry}</li>
        ))}
      </ul>
      <LoadMore>
        {shown < ENTRIES.length ? (
          <Button
            variant="secondary"
            size="sm"
            onClick={() => setShown(shown + STEP)}
          >
            Load more
          </Button>
        ) : (
          "End of the audit log"
        )}
      </LoadMore>
    </div>
  )
}
<script setup lang="ts">
import { ref } from "vue"
import { Button } from "~~/registry/bases/newt/ui/button"
import { LoadMore } from "~~/registry/bases/newt/ui/pagination"

/*
 * `LoadMore` is a row, not a button: it holds the control while there is more
 * to fetch, and the closing line once the list has reached its end.
 */
const entries = [
  "Ada changed the server name",
  "Lin created #announcements",
  "Ada gave Sol the Moderator role",
  "Sol deleted 4 messages in #lounge",
  "Lin updated the welcome screen",
  "Sol timed out a member for 10 minutes",
  "Ada created an invite that never expires",
  "Lin renamed #general to #lobby",
]
const step = 3
const shown = ref(step)
</script>

<template>
  <div class="flex w-full max-w-sm flex-col">
    <ul class="flex flex-col gap-2 text-sm text-newt-text-secondary">
      <li v-for="entry in entries.slice(0, shown)" :key="entry">
        {{ entry }}
      </li>
    </ul>
    <LoadMore>
      <Button
        v-if="shown < entries.length"
        variant="secondary"
        size="sm"
        @click="shown += step"
      >
        Load more
      </Button>
      <template v-else>End of the audit log</template>
    </LoadMore>
  </div>
</template>

API reference

Pagination

PropType
children / default slot?React.ReactNode / Vue slot

Content rendered inside the component.

TypeReact.ReactNode / Vue slot
className / class?string

Additional classes merged with the component defaults.

Typestring

The registry exports Pagination, PaginationButton, PaginationEllipsis, LoadMore. Parts without a table accept the native attributes for the element they render; React uses className, while Vue uses class and fallthrough attributes.

Accessibility

Label the navigation region and mark the current page with aria-current="page". Previous and next controls need descriptive accessible names.

Pass aria-label to Pagination to replace its English name, Pagination. Translating labels lists every English default.

Tokens

Pagination reads its colours, radii and motion from the --newt-* tokens installed with the library. Override a token and every component that reads it follows, including this one — see the token layer. In the plain HTML and CSS distribution the same component is newt-pagination.

  • --newt-text-secondary
  • --newt-bg-elevated
  • --newt-border
  • --newt-radius-sm
  • --newt-bg-hover
  • --newt-text-primary
  • --newt-brand
  • --newt-on-accent
  • --newt-text-muted