Skip to
Keyboard shortcuts

Use the up and down arrow keys to move between items. Press Alt+Shift+K to open this list again.

Alpha version out now. The API may still change.

Pagination

A named landmark with a list of links for moving through a long list page by page. Every page is a link to its own address, so Back, sharing and opening in a new tab work. The current page has a filled shape and heavier text as well as its colour.

Package
@kvirn-ui/react
Testing
Automated. Core 0 of 2, Release 0 of 3

When to use it#

  • Use it under a list that continues on other pages: news, search results, a register of cases.
  • Every page is a link to its own address, a path or a query. If paging doesn’t change the address, it is not pagination.
  • You decide which numbers to show: keep the first and last page and those next to the current one, with an ellipsis (“…”) for each gap. Leave out Previous on the first page and Next on the last, never disable them.
  • On a screen narrower than 40rem (640 pixels at the default text size) the theme shows only Previous, the current page, the status and Next. Always render Pagination.Status too, so people on a phone see how many pages there are. From 40rem the total is the last page link, so keep it.
  • Not for steps in a form or a flow. Not for the sections of a site: use Navigation. Not for the way up the structure: use Breadcrumb.

Example#

Information: Implement like this

Register your router’s link once on the provider and every link here is rendered by it, so a click doesn’t reload the page. See the Next.js setup on KvirnProvider.

Use cases#

A news list with ten pages

With many pages, show the first and the last page and the pages around the current one. Put a Pagination.Ellipsis in each gap. A gap is its own item with the text …, so a screen reader counts it in the list and reads it as punctuation, or pauses. The page numbers around it show which pages are left out. Don’t hide it: an empty item is read as “blank”. To have it spoken as words, give Ellipsis your own text in a VisuallyHidden next to an aria-hidden …. It is not a link and not a Tab stop. The filled current page shows where you are, and on a narrow screen the status does too.

Props in this example:

  • page on Pagination.Link
  • current on Pagination.Link
  • page on Pagination.Status
  • total on Pagination.Status

Information: Did you know?

The current page stays a link, so it is a Tab stop and its address can be copied. It has aria-current="page", which a screen reader announces itself, so its name stays “Page 5”. The digit people see is in the name (2.5.3 Label in Name, A).

Search results that keep the search

The library draws the links you give it and doesn’t count pages, so calculate the numbers from the current page and the total: the first and last page, the one before and after the current page, and an ellipsis where two or more pages are left out. Build every address from the search the visitor made, so Back, a copied link and a new tab open the same results.

Props in this example:

  • page on Pagination.Link
  • current on Pagination.Link
  • page on Pagination.Status
  • total on Pagination.Status

Information: Did you know?

A page is a URL, so a link that drops the search words or the filter opens a different list. Put them in every link, next to the page number.

The first page of a short list

On the first page there is no page before, so leave Previous out instead of disabling it. A link can’t be disabled, and a dimmed one would lead nowhere. Do the same with Next on the last page. With three pages there is no gap to mark.

Props in this example:

Warning: Don't forget

Mark exactly one page as current, and list the pages in order, lowest first.

Your own words for the controls

Previous, Next and the status come from the library’s messages in five languages. To use other words, pass children, or override the message with messages on the part or on the provider. Say where the link leads, such as “Previous results”, and not just “Back” (2.4.4 Link Purpose (In Context), A).

Props in this example:

Warning: Don't forget

Words you write are your own text. If their language differs from the page, put them in a nested KvirnProvider and spread useLocale().localeProps on your own element around them (3.1.2 Language of Parts, AA).

Two lists on one page

A case page can hold messages and documents, each with its own pages. Give each Pagination its own label, and put the page of both lists in every address, so paging one list leaves the other where it was.

Messages about your case

Documents in your case

Props in this example:

Information: Did you know?

Without a label every Pagination is named by the message pagination.label (“Pages”), so a screen reader’s list of landmarks shows the same name twice.

Accessibility#

What it does for you#

  • APG pattern: none. A labelled <nav> around a list of links is plain HTML; the current page is marked with aria-current="page" as in GOV.UK and Designsystemet.
  • Deviations: none. Pages are URLs, so each is a link and none is a button: Back, sharing and opening in a new tab work.
  • Native elements used: <nav> (the navigation landmark), <ul> and <li>. The links are Link: native <a href>, rendered by the registered router link.

Pagination lets a resident move through a long list. It adds no tabindex, no key handling and no live announcement: the links are the focusable parts and own the keys. Which numbers and gaps to show is the consumer's.

PartElement / roleARIANotes
Pagination.Root<nav> → navigationaria-label from label or pagination.labelclass="kv-pagination". Named, and distinct from the main navigation and the breadcrumb
Pagination.List<ul> → listrole="list"The count of items is announced. The explicit role="list" keeps the list announced in Safari/VoiceOver, which drops it from a list with list-style: none (1.3.1 Info and Relationships, A)
Pagination.Item<li> → listitemnoneHolds one link, the gap or the status
Pagination.Link<a href> → linkaria-label Page N (none with your own children); aria-current="page" on the current oneA page: shows the number, named Page 2. current adds aria-current, which a screen reader announces itself, so the name does not repeat it. The visible number is in the name (2.5.3 Label in Name, A). Your own children replace the number and the aria-label, so the visible text is the name. It stays a link and a Tab stop
Pagination.Previous<a href> → linknoneVisible words Previous page, rel="prev". An arrow drawn by the theme is CSS content with an empty alternative
Pagination.Next<a href> → linknoneVisible words Next page, rel="next"
Pagination.Ellipsis<span>noneThe text … for a gap in the numbers, in its own list item, so the list's item count matches what is shown. Not a link, not focusable, not hidden from assistive technology. Screen readers read … by their punctuation setting ("dot dot dot", "ellipsis", or a pause). The page link names carry the gap as well. To speak words instead, pass children: <span aria-hidden="true">…</span> plus VisuallyHidden text from your messages
Pagination.Status<span>noneText such as Page 2 of 9. Shown with Previous, Next and the current page below 40rem, where the other numbers are hidden. Without it a narrow screen has no total (a development warning says so). From 40rem the total is the last page link, so keep it
Partsas on the link parts onlynoneThe link parts are Link.Root wrappers with the same props, ref and as (as="a" bypasses the router). Root, List, Item, Ellipsis and Status have no as: the landmark and the list are fixed by the contract

It announces nothing.

What you need to do#

  • Every page is a URL (a query or a path), so Back, a bookmark and "open in new tab" work. No onClick that pages without changing the address.
  • Mark exactly one page current, and list the page links in order. Keep the first and last page and the pages next to the current one, with Pagination.Ellipsis for each gap.
  • Previous and Next are omitted (not disabled) on the first and last page: a link can't be disabled, and a dimmed one would lead nowhere.
  • Put it in the same place on every page that has a list, so people find it where they expect it.
  • Render Pagination.Status as well so the narrow layout has its text: it is hidden by the theme from 40rem.
  • Language. A custom children or messages string is your own: put it in a nested KvirnProvider with useLocale().localeProps on your own element if it differs from the page (3.1.2 Language of Parts, AA). Changing a visible label also changes its name (2.5.3 Label in Name, A). A page link with your own children has no aria-label: the text you write is the name, so it must contain the visible name: an icon-only or aria-hidden-only child leaves the link unnamed.
  • Keep the look in a custom theme. See Visual / modes.

Warning: Don't forget

Always render Pagination.Status. Below 40rem the page numbers are hidden, so without it a phone shows no total. A development warning says so when it is missing (1.3.1 Info and Relationships, A).

Visual and modes#

  • Focus indicator: a link shows the focus ring (:focus-visible), through Link.
  • Target size: 44 pixels high by default, 24 by 24 pixels at minimum (2.5.8 Target Size (Minimum), AA).
  • Current page: a shape and aria-current, never colour alone (1.4.1 Use of Color, A).
  • Reflow: the links wrap, and below 40rem only Previous, the current page, the status and Next show (1.4.10 Reflow, AA). The reflow sweep runs the narrow layout at 320 CSS px and fails on horizontal overflow.
  • Forced colours and reduced motion: the links follow the system colours. In forced colours the fill drops and the current page shows a bar in the link colour under its number (checked by eye). The forced-colours sweep checks that each link has a visible boundary or distinct text and that the focus ring is drawn; the reduced-motion sweep checks that nothing animates.

A custom theme must keep these.

Focus management#

  • Initial focus: not moved. Focus is never moved by the component. After a client-side navigation the consumer's route handling moves focus to the new content (2.4.3 Focus Order, A).
  • Trap: no. Restore to: not applicable.
  • A link shows the focus ring (:focus-visible), through Link.

Warning: Don't forget

When a page link shows new results without reloading the page, focus stays on the link you pressed and a screen reader says nothing. Move focus to the new content yourself, for example with Route focus (2.4.3 Focus Order, A).

WCAG success criteria#

1.3.1 Info and Relationships (A): a landmark and a list. 1.4.1 Use of Color (A): the current page is a filled shape and a weight, not colour. 1.4.10 Reflow (AA): the links wrap, and below 40rem only Previous, the current page, the status and Next show. 2.4.3 Focus Order (A). 3.2.3 Consistent Navigation (AA): the consumer rule to put it in the same place on every page. 2.4.4 Link Purpose (In Context) (A): Page 2. 2.5.3 Label in Name (A): the visible number is in the name. 2.5.8 Target Size (Minimum) (AA). 3.1.2 Language of Parts (AA): a custom label in another language is marked by the consumer. 4.1.2 Name, Role, Value (A). 2.4.8 Location (AAA, beyond the AA bar): the current page and the total show where you are. Designed and tested to meet WCAG 2.2 AA.

Keyboard#

Focus
native
Selection follows focus
n/a
Arrows wrap
n/a
Shortcuts
none

Native tab order. No key is intercepted, and the arrow keys do nothing.

KeyWhereWhat happens
Tabbefore / on the pagesMoves to the next link in order, the current page included. The ellipsis and status are not stops
Test: pagination.test.tsx › Pagination keyboard › Tab moves through every link in order, and the ellipsis and status are no stops
Tabon the current pageThe current page is a link, so it is a Tab stop
Test: pagination.test.tsx › Pagination keyboard › the current page is a link and a Tab stop
Shift+Tabon a linkMoves to the previous link
Test: pagination.test.tsx › Pagination keyboard › Shift+Tab moves to the previous link
Enteron a linkFollows it: a router link navigates without a page load, and focus stays on the link
Test: pagination.test.tsx › Pagination keyboard › Enter follows a link through the registered router link, without a page load
Spaceon a linkNot handled (a link: the page scrolls natively)
Test: pagination.test.tsx › Pagination keyboard › Space is not handled

API reference#

import { Pagination, usePagination } from '@kvirn-ui/react'

Pagination.Root

Renders <nav>, the navigation landmark, named by the message pagination.label or your label. It takes every attribute of a <nav> and passes ref to it. The default theme is described on Theming.

PropTypeDefaultDescription
labelstringthe message pagination.labelThe accessible name, from your translations. Set as aria-label. An empty or whitespace-only label counts as none. Name two paginations on one page differently.
messagesPartial<KvirnMessages['pagination']>–Per-instance message overrides.
Class or attributeValuesMeaning
kv-paginationalwaysThe part class. The default theme styles it.
aria-labelthe nameAlways set, from label or the message pagination.label.

Pagination.List

Renders <ul> with the role list. Previous, the pages, the status and Next each go in a Pagination.Item.

Class or attributeValuesMeaning
kv-pagination-listalwaysThe part class.
role"list"Always set. Safari with VoiceOver drops the list role from a list without markers, so it is written out.

Pagination.Item

Renders <li> with the role listitem. It holds one link, the gap or the status.

Class or attributeValuesMeaning
kv-pagination-itemalwaysThe part class.

Renders <a href> for one page: a thin wrapper over Link.Root, so it is rendered by the router link you register on the provider. It takes the other props and ref of Link.Root, except current, which is a boolean here. Pass as="a" to skip the router link.

PropTypeDefaultDescription
pagenumberRequiredThe page this link goes to, from 1. It is the link’s text, through the locale’s number format, and with the message its name: Page 2.
currentbooleanfalseThis link is the current page. It stays a link, and gets aria-current="page" and the name Page 2 (the current state is aria-current, not repeated in the name).
messagesPartial<KvirnMessages['pagination']>–Overrides pagination.page for this link.
childrenReactNodethe page numberYour own text. It replaces the number and the aria-label, so the text you write is the link’s name. Keep it a real name: an icon alone leaves the link unnamed.
Class or attributeValuesMeaning
kv-pagination-linkalwaysThe part class, next to kv-link.
aria-label"Page 2", or absentFrom the message pagination.page. Not set when you give your own children.
aria-current"page" or absentFrom current.

Pagination.Previous

Renders <a href> to the previous page, with the words from the message pagination.previous. It takes the other props and ref of Link.Root.

PropTypeDefaultDescription
messagesPartial<KvirnMessages['pagination']>–Overrides pagination.previous for this link.
childrenReactNodethe message pagination.previousYour own text. Its language is yours to set.
Class or attributeValuesMeaning
kv-pagination-previousalwaysThe part class, next to kv-link. The theme draws the arrow.
rel"prev"Always set.

Pagination.Next

Renders <a href> to the next page, with the words from the message pagination.next. It takes the other props and ref of Link.Root.

PropTypeDefaultDescription
messagesPartial<KvirnMessages['pagination']>–Overrides pagination.next for this link.
childrenReactNodethe message pagination.nextYour own text. Its language is yours to set.
Class or attributeValuesMeaning
kv-pagination-nextalwaysThe part class, next to kv-link. The theme draws the arrow.
rel"next"Always set.

Pagination.Ellipsis

Renders <span> with the text “…”, for a gap in the page numbers. It is not a link and not focusable.

PropTypeDefaultDescription
childrenReactNode…Your own text for the gap.
Class or attributeValuesMeaning
kv-pagination-ellipsisalwaysThe part class.

Pagination.Status

Renders <span> with the text from pagination.status, such as “Page 2 of 9”. The default theme shows it, with Previous, Next and the current page, below 40rem, and hides it on wider screens, where the last page link gives the total.

PropTypeDefaultDescription
pagenumberRequiredThe page you are on, from 1.
totalnumberRequiredHow many pages there are.
messagesPartial<KvirnMessages['pagination']>–Overrides pagination.status for this status.
childrenReactNodethe message pagination.statusYour own text. Its language is yours to set.
Class or attributeValuesMeaning
kv-pagination-statusalwaysThe part class. The default theme shows it below 40rem, with Previous, Next and the current page, and hides it on wider screens.

usePagination

Options

PropTypeDefaultDescription
labelstringthe message pagination.labelThe accessible name, set as aria-label. An empty label counts as none.
messagesPartial<KvirnMessages['pagination']>–Per-instance message overrides: { next: "Next results" }.

Result

PropTypeDefaultDescription
rootPropsPaginationRootPartProps–Spread on the <nav>: the class and aria-label.
listPropsPaginationListPartProps–Spread on the <ul>: the class.
itemPropsPaginationItemPartProps–Spread on every <li>: the class.
ellipsisPropsPaginationEllipsisPartProps–Spread on the gap’s <span>: the class.
statusPropsPaginationStatusPartProps–Spread on the status <span>: the class.
labelstring–The resolved name of the landmark.
previousLabelstring–The message pagination.previous: the text of the Previous link.
nextLabelstring–The message pagination.next: the text of the Next link.
getPageLabel(page: number) => string–The name of a page link: Page 2. The current page gets aria-current="page" instead of a longer name.
getStatus(page: number, total: number) => string–The status text: Page 2 of 9.

Strings

These are the default texts in @kvirn-ui/i18n.

For your whole app, pass messages to KvirnProvider. For one Pagination, pass its messages prop.

pagination.label

The landmark’s accessible name, set as aria-label.

LanguageDefault text
SvenskaSidor
SuomiSivut
Norsk bokmålSider
Norsk nynorskSider
EnglishPages

pagination.previous

The visible text of the Previous link.

LanguageDefault text
SvenskaFöregående sida
SuomiEdellinen sivu
Norsk bokmålForrige side
Norsk nynorskFørre side
EnglishPrevious page

pagination.next

The visible text of the Next link.

LanguageDefault text
SvenskaNästa sida
SuomiSeuraava sivu
Norsk bokmålNeste side
Norsk nynorskNeste side
EnglishNext page

pagination.status

The status text, shown on a narrow screen instead of most page links.

LanguageDefault text
SvenskaSida 2 av 9
SuomiSivu 2/9
Norsk bokmålSide 2 av 9
Norsk nynorskSide 2 av 9
EnglishPage 2 of 9

pagination.page

The name of a page link. The visible number stays in the name.

LanguageDefault text
SvenskaSida 2
SuomiSivu 2
Norsk bokmålSide 2
Norsk nynorskSide 2
EnglishPage 2

Testing#

The automated tests prove the keyboard behaviour, the names and states, that axe finds no violations in every story and theme, and, for the components they cover, that the stories hold up in forced colours, reduced motion, text spacing and a 320 pixel width. An Automated row passes on these tests alone. A Core or Release row passes only when an automated agent check and a person on the real assistive technology have both checked it. "agent-verified" means automated tests in the repository (with a virtual screen reader for the screen reader rows), not the real assistive technology.

AT + browser + OSAgent checkHuman checkResultNotes
Automated (re-runnable tests)
axe, WCAG 2.2 A and AA, every story, 4 themespassn/apasspagination.stories.tsx, every story, 4 themes
Markup and ARIA (roles, names, ids, states)passn/apasspagination.test.tsx › is a navigation landmark named by the message pagination.label; expectNoA11yViolations
Keyboard contract rows (Vitest browser)passn/apass5 rows, each names a test (pagination.test.tsx › Pagination keyboard › Tab moves through every link in order, and the ellipsis and status are no stops)
Focus order and managementpassn/apasspagination.test.tsx asserts focus (toHaveFocus); first rule: Pagination keyboard › Tab moves through every link in order, and the ellipsis and status are no stops
Display modes (forced colours, 320px reflow, text spacing, reduced motion)passn/apassthe four sweep projects (storybook-forced-colors, -reduced-motion, -reflow, -text-spacing), run in CI
Core (required for beta)
NVDA + Chrome + Windowspendingpendingpending
VoiceOver + Safari + iOSpendingpendingpending
Release (before 1.0 and each minor)
JAWS + Chrome + Windowspendingpendingpending
TalkBack + Chrome + Androidpendingpendingpending
VoiceOver + Safari + macOSpendingpendingpending

What to check#

With a screen reader and the keyboard, try:

  • Tab reaches Previous, each page number and Next once. The gap and the status text are not stops.
  • The current page is announced as current, and its name still has the number.
  • Press Enter on a page link: the list and the address change, and Back returns. Note where focus lands and whether you hear the change.
  • The landmarks list shows Pagination with its own name, and two on a page differ.
  • At 320px only Previous, the current page, "Page N of M" and Next show, with no sideways scroll.
  • In forced colours the current page still stands out.