Skip to content

Pagination ​

Links to the pages of a long list, with previous and next, the current page and a gap.

Installation ​

bash
npx bootcn add pagination
bash
pnpm dlx bootcn add pagination
bash
yarn dlx bootcn add pagination
bash
bunx --bun bootcn add pagination

The CLI also installs the design tokens and these components: none. It prints the <link> and <script> tags to add to your layout.

Usage ​

Render the page links on the server. Mark the current page with active on its .page-item and aria-current="page" on its link. Leave out Previous on the first page and Next on the last (or render them as disabled items).

Accessibility ​

  • A <nav aria-label="Pagination"> landmark around a list of links.
  • Previous and Next are named "Previous page" and "Next page"; on phones their text is visually hidden but still read.
  • The gap ("…") is hidden from screen readers.

Dependencies ​

  • Bootstrap 5.3+ CSS.
  • themes/tokens/tokens.css.

Source ​

The exact files the CLI installs (pagination@1.0.0). View on GitHub · Report an issue

html
<nav aria-label="Pagination">
  <ul class="pagination bootcn-pagination">
    <li class="page-item">
      <a class="page-link bootcn-pagination__step" href="#page-1" aria-label="Previous page">
        <svg
          class="bootcn-icon"
          width="16"
          height="16"
          viewBox="0 0 24 24"
          fill="none"
          stroke="currentColor"
          stroke-width="2"
          stroke-linecap="round"
          stroke-linejoin="round"
          aria-hidden="true"
          focusable="false"
        >
          <path d="m15 18-6-6 6-6" />
        </svg>
        <span class="bootcn-pagination__step-text">Previous</span>
      </a>
    </li>
    <li class="page-item"><a class="page-link" href="#page-1">1</a></li>
    <li class="page-item active"><a class="page-link" href="#page-2" aria-current="page">2</a></li>
    <li class="page-item"><a class="page-link" href="#page-3">3</a></li>
    <li class="page-item">
      <span class="page-link bootcn-pagination__gap" aria-hidden="true">…</span>
    </li>
    <li class="page-item"><a class="page-link" href="#page-12">12</a></li>
    <li class="page-item">
      <a class="page-link bootcn-pagination__step" href="#page-3" aria-label="Next page">
        <span class="bootcn-pagination__step-text">Next</span>
        <svg
          class="bootcn-icon"
          width="16"
          height="16"
          viewBox="0 0 24 24"
          fill="none"
          stroke="currentColor"
          stroke-width="2"
          stroke-linecap="round"
          stroke-linejoin="round"
          aria-hidden="true"
          focusable="false"
        >
          <path d="m9 18 6-6-6-6" />
        </svg>
      </a>
    </li>
  </ul>
</nav>
css
.bootcn-pagination {
  --bs-pagination-padding-x: 0.75rem;
  --bs-pagination-padding-y: 0.375rem;
  --bs-pagination-font-size: 0.875rem;
  --bs-pagination-color: var(--bootcn-foreground);
  --bs-pagination-bg: transparent;
  --bs-pagination-border-width: var(--bootcn-border-width);
  --bs-pagination-border-color: transparent;
  --bs-pagination-border-radius: var(--bootcn-radius);
  --bs-pagination-hover-color: var(--bootcn-accent-foreground);
  --bs-pagination-hover-bg: var(--bootcn-accent);
  --bs-pagination-hover-border-color: transparent;
  --bs-pagination-focus-color: var(--bootcn-foreground);
  --bs-pagination-focus-bg: transparent;
  --bs-pagination-focus-box-shadow: var(--bootcn-focus-ring);
  --bs-pagination-active-color: var(--bootcn-foreground);
  --bs-pagination-active-bg: var(--bootcn-background);
  --bs-pagination-active-border-color: var(--bootcn-input);
  --bs-pagination-disabled-color: var(--bootcn-muted-foreground);
  --bs-pagination-disabled-bg: transparent;
  --bs-pagination-disabled-border-color: transparent;

  flex-wrap: wrap;
  gap: 0.25rem;
  margin: 0;
}

/* Separate rounded buttons instead of Bootstrap's joined strip. */
.bootcn-pagination .page-item .page-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  min-width: 2.25rem;
  height: 2.25rem;
  margin-left: 0;
  border-radius: var(--bs-pagination-border-radius);
  font-weight: 500;
}

.bootcn-pagination .page-item.active .page-link {
  box-shadow: var(--bootcn-shadow-sm);
}

.bootcn-pagination__gap {
  pointer-events: none;
}

@media (max-width: 575.98px) {
  .bootcn-pagination__step-text {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }
}

Released under the MIT License. Not affiliated with Bootstrap or shadcn/ui.