Skip to Content
CodeUI

Pagination

@codeui/solid v0.3.0

Page buttons with previous, next, and optional boundary controls.

When to use

Use Pagination to select a page of snippets or search results when you know the total page count.

When to choose another component

Use a load-more button for an unknown total. Use Tabs for named panels rather than numbered result pages.

Live demo

Snippet page 1 of 12

pagination/basic.tsx
import { Pagination } from "@codeui/solid";
import { createSignal } from "solid-js";
export default function Basic() {
	const [page, setPage] = createSignal(1);
	return <div><Pagination pages={12} page={page()} onChange={setPage} /><p>Snippet page {page()} of 12</p></div>;
}

Pages start at 1. The controlled page updates through onChange. Fetch or slice your result data in the parent.

Anatomy

Tap a part to outline it in the demo.

  1. 01Paginationpagination
  2. 02IconButtonpagination-item
ExportRendersclasses keydata-cuiRole
Paginationnavnonepaginationnavigation
Internal IconButtonbuttonnonepagination-itembutton

Pagination does not accept class, classes, or arbitrary DOM props. Wrap it when you need layout styles.

Variants

Numeric window and sibling counts

One sibling on either side

Two siblings on either side

Hide unavailable navigation

pagination/window.tsx
import { Pagination } from "@codeui/solid";
export default function Window() {
	return <div><p>One sibling on either side</p><Pagination pages={20} initialPage={10} maxPages={3} /><p>Two siblings on either side</p><Pagination pages={20} initialPage={10} maxPages={5} /><p>Hide unavailable navigation</p><Pagination pages={20} showPrev={page => page > 1} showNext={(page, pages) => page < pages} /></div>;
}

maxPages limits numeric buttons. The default is five. Navigation buttons do not count toward that limit. There is no siblingCount prop. Away from the boundaries, maxPages={3} gives one sibling on each side and maxPages={5} gives two. Near either boundary, the window shifts to keep the available numeric buttons visible. It does not render ellipses.

Sizes and rounded buttons

xs

sm

md

lg

pagination/sizes.tsx
import { Pagination } from "@codeui/solid";
import { For } from "solid-js";
export default function Sizes() {
	return <For each={["xs", "sm", "md", "lg"] as const}>{size => <div><p>{size}</p><Pagination pages={3} size={size} rounded /></div>}</For>;
}

Pagination uses the Button scale with an sm default. rounded makes each button a pill.

States

First page

Last page

One page

pagination/boundaries.tsx
import { Pagination } from "@codeui/solid";
export default function Boundaries() {
	return <div><p>First page</p><Pagination pages={12} initialPage={1} maxPages={3} showFirst showLast /><p>Last page</p><Pagination pages={12} initialPage={12} maxPages={3} showFirst showLast /><p>One page</p><Pagination pages={1} showFirst showLast /></div>;
}

Previous and first controls disable on page 1. Next and last controls disable on the last page. For a single page, all navigation controls disable. Visibility callbacks can hide controls at boundaries instead. Supply a positive page count. For zero results, render an empty state and omit Pagination.

Ready API

Pagination

Renders numbered buttons and optional navigation controls inside a navigation landmark.

Prop

Type

Prop

Type

The component uses createPagination from @solid-primitives/pagination, rather than Kobalte. showFirst, showPrev, showNext, and showLast accept booleans or functions of the current page and page count.

Styled parts API

Use @codeui/solid/pagination/parts to control the navigation layout. Call createPaginationState with the page count and any controlled page props. Use its items() to render Item buttons in Root. The state also exposes page() and setPage for other controls in the same component. Set an accessible label on the navigation and give any icon-only navigation button a label.

Accessibility

Keyboard

KeyAction
Tab, Shift + TabMoves between enabled page buttons.
Enter, SpaceActivates the focused button.

ARIA

The root is a navigation landmark. Numbered buttons receive names such as Page 3 and Page 3 active. The current numeric button receives aria-current. Boundary controls use native disabled buttons. The navigation landmark has no built-in accessible label and the public API does not forward one.

Focus

Changing page does not move focus to the result region. Keep a result heading and status message in the parent when loading another page. There is no open or close cycle.

SSR notes

The navigation landmark and initial page buttons render on the server. Keep pages and the initial page equal on the server and client. There is no portal. Page changes run on the client.

Theming hooks

Pagination reads --cui-space-0-5 for gaps and inherits the IconButton styles. The active button uses the primary variant. Other buttons use the secondary variant. It reserves numeric widths with tabular numbers.

Composition examples

The main demo places a page summary beside controlled Pagination. Use the same page signal to select results and update the summary.

  • Tabs switches named content panels.
  • IconButton supplies the page button styles.

On this page