Skip to content

shadcn.io is an independent project built on shadcn/ui

Components

Free

Pagination for Svelte UI SDK

Page links for Svelte on UI SDK: previous, next, the numbered pages and an ellipsis for the gaps, with the current page marked for screen readers.

On this page9 sections

Pagination splits a long list across numbered pages and gives people the controls to move through them: previous and next, the page numbers, and an ellipsis where the run is cut short. When each page is a link, page 12 has an address that can be bookmarked, shared and crawled.

It sits under search results, a Table of orders or a blog archive. For the steps of a single task, such as a checkout, use Steps instead.

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

Anatomy

Pagination anatomy: root, previous, item, ellipsis, next

Usage

<script lang="ts">
import {
  Pagination, PaginationContent, PaginationEllipsis, PaginationItem,
  PaginationLink, PaginationNext, PaginationPrevious,
} from "@/components/ui/pagination";
</script>

Wrap each control in its own PaginationItem, and mark the page on screen with isActive.

<Pagination>
  <PaginationContent>
    <PaginationItem>
      <PaginationPrevious href="?page=1" />
    </PaginationItem>
    <PaginationItem>
      <PaginationLink href="?page=1">1</PaginationLink>
    </PaginationItem>
    <PaginationItem>
      <PaginationLink href="?page=2" isActive>
        2
      </PaginationLink>
    </PaginationItem>
    <PaginationItem>
      <PaginationLink href="?page=3">3</PaginationLink>
    </PaginationItem>
    <PaginationItem>
      <PaginationEllipsis />
    </PaginationItem>
    <PaginationItem>
      <PaginationNext href="?page=3" />
    </PaginationItem>
  </PaginationContent>
</Pagination>

Accessibility

Pagination renders a nav landmark labeled pagination, and each page is a link in the tab order. isActive on a PaginationLink sets aria-current="page", which a screen reader announces, and PaginationEllipsis is hidden from screen readers. With count, UI SDK renders buttons instead: the current one carries aria-current, at either end Previous or Next gets aria-disabled and does nothing, and the translations prop can rename them.

In a row of links, PaginationPrevious and PaginationNext are named Go to previous page and Go to next page whatever their text says, and below the sm breakpoint, where the words hide, that name is their only label. On a page in another language, pass each a translated aria-label.

Demos

Simple

Five numbered links and nothing else, with page 2 marked by isActive, which outlines it and sets aria-current. A row of numbers suits a short run of five or six pages, where Previous and Next would only add width. Once the pages run past what fits, add Previous, Next and an ellipsis, as the preview at the top does.

Preview width

Icons only

Previous and Next with no page numbers, beside a Rows per page select set to 25, as in the footer of a data table. Their words hide below the sm breakpoint, leaving only the arrows. Use it when the table already shows which rows are on screen, and keep the numbers when people need to jump far ahead.

Preview width

RTL

The default row in Arabic, with dir set to rtl on Pagination, Arabic-Indic numerals and Arabic text on Previous and Next. The row starts at the right, and the arrows turn to point the way it reads. Those two are still named Go to previous page and Go to next page, so pass a translated aria-label alongside text.

Preview width

FAQ

How do I track the current page with the UI SDK Pagination?

Pass count, the total number of items, and UI SDK keeps the page for you. PaginationItems renders the numbered buttons and the ellipses, and Previous and Next disable themselves at the ends. Use bind:page to control it, or pass page with onPageChange, which receives the new page first, and set pageSize when it isn't the default of 10.

How do I show an ellipsis when Pagination has many pages?

With count, UI SDK works it out. siblingCount sets how many pages show on each side of the current one and boundaryCount how many at each end, 1 each by default, and PaginationItems puts a PaginationEllipsis in every gap. On page 10 of 20 that gives 1, an ellipsis, 9, 10, 11, an ellipsis and 20.

Why can I still click Previous on the first page?

Without count, Pagination is a row of links that doesn't know where it stands, so Previous stays live. Pass count and UI SDK marks Previous aria-disabled on the first page and Next on the last, and pressing them does nothing.

In a row of links, set aria-disabled to true and tabIndex to -1 on PaginationPrevious while on page 1. The button styles then fade it and ignore clicks, and Tab skips it. Do the same for PaginationNext on the last page, or leave either one out.

How do I show only Previous and Next buttons in Pagination?

Keep PaginationPrevious and PaginationNext and leave the numbered links out, as the Icons only demo does beside a rows-per-page select. Below the sm breakpoint their words hide and only the arrows show.

Without numbers, people can't tell how far along they are, so show the range on screen next to the buttons, such as 26 to 50 of 312.

How do I change or translate the Pagination labels?

Pass text to PaginationPrevious and PaginationNext for the visible words, Previous and Next by default, as the RTL demo does in Arabic. That changes only what is seen. The name a screen reader reads stays Go to previous page and Go to next page until you pass a translated aria-label as well.

The landmark itself is named pagination, so give Pagination a translated aria-label too. With count, the numbered buttons, Previous and Next take their names from the translations prop, and the aria-label you pass still names the landmark.

Should I use Pagination or infinite scroll?

Use pagination when people come back to a place in the list, compare items across pages or need what sits below the list: search results, an admin table, an archive. Each page has its own address, so the back button and a shared link land on the same items.

Infinite scroll suits a feed read once from the top. A Load more button sits between the two, keeping one address while letting people choose when to fetch more.

API Reference

Pagination

PropType
page?number

The current page, from 1. Pass it to control the pagination. Two-way with bind:page.

defaultPage?number

The page it starts on, when uncontrolled.

Default
1
onPageChange?(page: number, details: ChangeDetails<PaginationPageChangeReason>) → void

Runs when the page wants to change: a page link ("item-press"), the Previous, Next, First or Last part, or a controller ("imperative"). details.cancel() keeps the page, and stops a link from navigating.

Type
(page: number, details: ChangeDetails<PaginationPageChangeReason>) → void
Parameters

page – number

details – ChangeDetails<PaginationPageChangeReason>

Returns
void
boundaries?number

How many pages always show at each end.

Default
1
controller?PaginationController

Pages it from anywhere. Create one with createPaginationController().

debug?boolean

Logs every state change with its reason to the console, in development builds.

disabled?boolean

Whether every page and step does nothing, like a step at its end. A controller still pages it.

Default
false
getHref?(page: number) → string

The URL of a page. With it, parts are links: they navigate, open in a new tab with a modifier key, and work before JavaScript loads. Without it, they're buttons.

Parameters

page – number

Returns
string
pageCount?number

How many pages there are. Or pass total and pageSize.

pageSize?number

How many items fit on a page, with total.

Default
10
siblings?number

How many pages show on each side of the current one.

Default
1
total?number

How many items there are, for pageCount from pageSize.

render?Snippet<[{ props, state, children }]>

Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.

Type
Snippet<[{ props, state, children }]>
class?string

Merged with the part's classes.

PaginationContent

<ul> data-slot="pagination-content"

PropType
children?Snippet | ((state: PaginationState) → Snippet)

Content, or a function of the pagination's page, pageCount and items.

Type
Snippet | ((state: PaginationState) → Snippet)
render?Snippet<[{ props, state, children }]>

Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.

Type
Snippet<[{ props, state, children }]>
class?string

Merged with the part's classes.

PaginationItem

<li> data-slot="pagination-item"

PropType
render?Snippet<[{ props, state, children }]>

Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.

Type
Snippet<[{ props, state, children }]>

<a> data-slot="pagination-link"

PropType
isActive?boolean

Marks the link as the current page: outlined, and aria-current="page". With a page, the pagination knows the current page itself.

page?number

The page it goes to, from 1, in a pagination with a pageCount. It shows the number unless it has children.

render?Snippet<[{ props, state, children }]>

Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.

Type
Snippet<[{ props, state, children }]>
class?string

Merged with the part's classes.

AttributeType
data-active?string

Mirrors isActive.

data-current?string

Present on the current page's link, beside aria-current="page".

PaginationPrevious

PropType
isActive?boolean

Marks the link as the current page: outlined, and aria-current="page". With a page, the pagination knows the current page itself.

page?number

The page it goes to, from 1, in a pagination with a pageCount. It shows the number unless it has children.

text?string

The button's label, beside its arrow.

Default
"Previous"
render?Snippet<[{ props, state, children }]>

Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.

Type
Snippet<[{ props, state, children }]>
class?string

Merged with the part's classes.

AttributeType
data-icon"inline-start"
Default
"inline-start"

PaginationNext

PropType
isActive?boolean

Marks the link as the current page: outlined, and aria-current="page". With a page, the pagination knows the current page itself.

page?number

The page it goes to, from 1, in a pagination with a pageCount. It shows the number unless it has children.

text?string

The button's label, beside its arrow.

Default
"Next"
render?Snippet<[{ props, state, children }]>

Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.

Type
Snippet<[{ props, state, children }]>
class?string

Merged with the part's classes.

AttributeType
data-icon"inline-end"
Default
"inline-end"

PaginationEllipsis

<span> data-slot="pagination-ellipsis"

PropType
class?string

Merged with the part's classes.