Search docs

Pagination

Navigation for moving across pages of content, supporting both button-based state updates and link-based navigation.

Pagination uses a <nav> landmark, native <button> or <a> elements, aria-current="page" on the active page, and aria-hidden="true" on ellipsis indicators.

import { component$, useSignal, useStyles$ } from '@builder.io/qwik';
import { getPaginationRange, Pagination } from '@leve-ui/pagination';
import { LuChevronLeft, LuChevronRight, LuMoreHorizontal } from '@qwikest/icons/lucide';
import styles from './default.css?inline';

export default component$(() => {
  useStyles$(styles);
  const page = useSignal(1);
  const totalPages = 10;
  const range = getPaginationRange({ page: page.value, totalPages });

  return (
    <Pagination.Root totalPages={totalPages} bind:page={page} class="pagination-default">
      <Pagination.List class="pagination-default-list">
        <li>
          <Pagination.PrevTrigger class="pagination-default-trigger" aria-label="Previous page">
            <LuChevronLeft class="pagination-default-icon" aria-hidden="true" />
          </Pagination.PrevTrigger>
        </li>
        {range.map((entry) =>
          entry.type === 'ellipsis' ? (
            <li key={entry.key}>
              <Pagination.Ellipsis class="pagination-default-ellipsis">
                <LuMoreHorizontal class="pagination-default-icon" aria-hidden="true" />
              </Pagination.Ellipsis>
            </li>
          ) : (
            <li key={entry.value}>
              <Pagination.Item value={entry.value} class="pagination-default-item">
                {entry.value}
              </Pagination.Item>
            </li>
          ),
        )}
        <li>
          <Pagination.NextTrigger class="pagination-default-trigger" aria-label="Next page">
            <LuChevronRight class="pagination-default-icon" aria-hidden="true" />
          </Pagination.NextTrigger>
        </li>
      </Pagination.List>
    </Pagination.Root>
  );
});

Installation#

Install the individual package, or use @leve-ui/core to get every component at once:

pnpm add @leve-ui/pagination

Anatomy#

import { Pagination } from '@leve-ui/pagination'; // or '@leve-ui/core'

<Pagination.Root totalPages={10}>
  <Pagination.List>
    <li>
      <Pagination.PrevTrigger />
    </li>
    <li>
      <Pagination.Item value={1}>1</Pagination.Item>
    </li>
    <li>
      <Pagination.Ellipsis />
    </li>
    <li>
      <Pagination.NextTrigger />
    </li>
  </Pagination.List>
</Pagination.Root>
PartElementDescription
Pagination.Root<nav>The navigation landmark that manages page state and total pages.
Pagination.List<ul>The unordered list of pagination controls. Wrap items, triggers, and ellipses in <li>.
Pagination.Item<button> / <a>A control for a specific page number. Renders <a> when href is provided, or <button type="button"> otherwise.
Pagination.PrevTrigger<button> / <a>Navigates to the previous page. Automatically disabled on the first page.
Pagination.NextTrigger<button> / <a>Navigates to the next page. Automatically disabled on the last page.
Pagination.Ellipsis<span>Decorative indicator for omitted pages, hidden from assistive technologies.

Examples#

Controlled#

Bind a Signal<number> with bind:page to read and control the current page from outside:

Page 3 of 8

Pass href to Pagination.Item, Pagination.PrevTrigger, and Pagination.NextTrigger to render <a> elements. You can also pass a router link component such as Qwik City's <Link> to as:

Pass a router link component such as Qwik City's <Link> to as on Pagination.Item, Pagination.PrevTrigger, and Pagination.NextTrigger for client-side navigation and prefetching while keeping Pagination's attributes:

import { Link } from '@builder.io/qwik-city';
import { Pagination } from '@leve-ui/pagination';

<Pagination.Root totalPages={8}>
  <Pagination.List>
    <li>
      <Pagination.PrevTrigger as={Link} href="/items?page=1">
        Previous
      </Pagination.PrevTrigger>
    </li>
    <li>
      <Pagination.Item as={Link} value={2} href="/items?page=2">
        2
      </Pagination.Item>
    </li>
    <li>
      <Pagination.NextTrigger as={Link} href="/items?page=3">
        Next
      </Pagination.NextTrigger>
    </li>
  </Pagination.List>
</Pagination.Root>

A component passed to as must spread the props it receives onto a single element, including id, aria-*, data-*, and on*$ event handlers.

Disabled#

Pass disabled on Pagination.Root to disable all interactive controls:

API Reference#

Root#

PropDefaultType
count–number

Total number of items. Used with pageSize when totalPages is not specified.

pageSize10number

Number of items per page.

totalPages–number

Total number of pages. Takes precedence over Math.ceil(count / pageSize).

defaultPage1number

Initial 1-based page number when uncontrolled.

bind:page–Signal<number>

A signal with the current 1-based page number (controlled).

onPageChange$–QRL<(page: number) => void>

Called when the current page changes.

disabledfalseboolean

Disables all interactive pagination controls.

Also accepts all <nav> attributes.

Data attributeValue
data-leve-paginationAlways present
data-disabledPresent when disabled is true

List#

No props of its own. Accepts all <ul> attributes.

Data attributeValue
data-leve-pagination-listAlways present

Item#

PropDefaultType
value (required)–number

1-based page number represented by this item.

href–string

Destination URL. When provided and as is omitted, renders an <a> element instead of <button>.

disabledfalseboolean

Disables this page item.

as–keyof HTMLElementTagNameMap | Component<any>

The element or component to render instead of <button> or <a>. A component must spread the props it receives onto one element.

Also accepts all <button> attributes.

Data attributeValue
data-leve-pagination-itemAlways present
data-state'selected' or 'unselected'
data-selectedPresent when the item represents the current page
data-disabledPresent when the item or Root is disabled

PrevTrigger#

PropDefaultType
href–string

Destination URL. When provided and as is omitted, renders an <a> element instead of <button>.

disabledfalseboolean

Disables the previous page trigger. Automatically disabled when on the first page.

as–keyof HTMLElementTagNameMap | Component<any>

The element or component to render instead of <button> or <a>. A component must spread the props it receives onto one element.

Also accepts all <button> attributes.

Data attributeValue
data-leve-pagination-prev-triggerAlways present
data-disabledPresent when on the first page, or when disabled is true

NextTrigger#

PropDefaultType
href–string

Destination URL. When provided and as is omitted, renders an <a> element instead of <button>.

disabledfalseboolean

Disables the next page trigger. Automatically disabled when on the last page.

as–keyof HTMLElementTagNameMap | Component<any>

The element or component to render instead of <button> or <a>. A component must spread the props it receives onto one element.

Also accepts all <button> attributes.

Data attributeValue
data-leve-pagination-next-triggerAlways present
data-disabledPresent when on the last page, or when disabled is true

Ellipsis#

No props of its own. Accepts all <span> attributes.

Data attributeValue
data-leve-pagination-ellipsisAlways present

getPaginationRange#

Pure helper function that computes the sequence of page numbers and ellipsis items to render:

import { getPaginationRange } from '@leve-ui/pagination';

const range = getPaginationRange({
  page: 5,
  totalPages: 10,
  siblingCount: 1,
  boundaryCount: 1,
});

Returns Array<{ type: 'page'; value: number } | { type: 'ellipsis'; key: string }>.

Accessibility#

  • Pagination.Root renders a <nav> landmark with aria-label="Pagination" by default. Pass aria-label or aria-labelledby to customize it.
  • The active Pagination.Item receives aria-current="page".
  • Pagination.Ellipsis renders aria-hidden="true" so screen readers skip decorative ellipsis indicators.
  • Disabled <button> controls use the native disabled attribute. Disabled <a> controls omit href, set aria-disabled="true" and tabIndex={-1}, and prevent click navigation.
  • Interactive controls are native <button> or <a> elements and are navigated with Tab / Shift+Tab and activated with Enter (or Space for buttons).