Skip to content
IndexRequest a UIAboutContact

Pagination

Page controls with previous and next, numbered pages and smart ellipsis.

Open alone ↗

AI prompt

PROMPT: PASTE INTO YOUR AI CODING TOOL
Build a pagination control for 20 pages inside a nav with aria-label="Pagination". Render Previous and Next buttons and numbered buttons computed by a function that always shows page 1, the last page, the current page and its two neighbours on each side, inserting a non-interactive ellipsis where numbers are skipped. The current page is a filled accent chip with aria-current="page". Disable Previous on the first page and Next on the last without removing them. Above the control show a mock list of five items that changes with the page, fading in over 140ms. Add a visually hidden aria-live="polite" region that announces "Page N of 20". On widths under 480px hide the numbered buttons and show "Page N of 20" text between Previous and Next. Minimum target size 40px. Honour prefers-reduced-motion.

About this pattern

Definition

A set of controls for moving between pages of a long list: previous and next buttons, the first and last page, and a window of numbers around the current page, with ellipses for the skipped ranges.

Purpose & UX principles

  • Splits a long list into pages the reader can reason about, and lets them jump to a known position.
  • Always show the current page, the first, the last, and one or two neighbours of the current page.
  • Disabled previous on page 1 and next on the last page, but keep them in place so the layout does not move.

Interaction states

  • Current page: filled accent chip with aria-current="page".
  • Disabled buttons: reduced opacity, disabled attribute.
  • Hover: surface lightens. Focus-visible: ring.
  • Live region announces "Page N of M" after each change.

Motion specification

  • Chip fill: 180ms background transition.
  • List content swaps with a 140ms fade.
  • Reduced motion: no fade.

Responsive behaviour

  • Phones: show previous, next and a text status such as "Page 4 of 20"; drop the number buttons.
  • Touch targets stay at least 40px.

Code

HTML
<div class="pg">
  <ul class="list" id="list" aria-live="off"></ul>
  <nav aria-label="Pagination" class="nav">
    <button id="prev" aria-label="Previous page">‹</button>
    <div class="nums" id="nums"></div>
    <span class="status" id="status"></span>
    <button id="next" aria-label="Next page">›</button>
  </nav>
  <p class="sr" id="live" aria-live="polite"></p>
</div>

Related patterns

Breadcrumb

↗
BreadcrumbNavigation

Tab Navigation

↗
Tab NavigationNavigation

Top Navigation

↗
Top NavigationNavigation