Skip to content
Likable Aurora @likable-hair/svelte 5

Paginator

Navigation between the pages of a paged list or table: first, previous, the page numbers, next and last. page starts from 1 and is bindable; onchange({ page }) is called when the user picks another page. With pageCount it shows the first and the last page, the current one with siblingCount pages on each side and "…" for the hidden ones, always the same number of items so the buttons do not move while paging; the arrows at the ends are disabled (aria-disabled, so they keep the focus). Without pageCount the total is unknown: it shows the previous, the current and the next page, and "next" is always enabled. The paginator never changes page on its own: when page is past pageCount no number is marked and "previous" goes to the last page. With pageHref the controls are links, so a page can live in the URL and open in a new tab. compact shows "7 / 24" between the arrows instead of the numbers. It is a <nav> named "Pagination" in the language of locale, the current page has aria-current="page". Its state is exposed as data-compact on the root and data-current on the current page for app CSS.

import { Paginator } from '@likable-hair/svelte';

src/lib/components/simple/navigation/Paginator.svelte · Markdown for LLMs

Pages of a list

bind:page holds the current page and pageCount the number of pages. The first and the last page are always there, the current one has a page on each side and "…" stands for the hidden ones, so the paginator keeps the same number of buttons while paging. Load the page in onchange.

Showing page 7 of 24

Code
<script lang="ts">
	import { Paginator } from '@likable-hair/svelte';

	let page = $state(7);
	let loaded = $state(7);
</script>

<div class="list">
	<Paginator bind:page pageCount={24} onchange={(event) => (loaded = event.page)} />
	<p>Showing page {loaded} of 24</p>
</div>

<style>
	.list {
		display: flex;
		flex-direction: column;
		gap: 12px;
	}

	p {
		margin: 0;
		color: var(--global-color-text-2);
		font-size: 13px;
	}
</style>

Unknown number of pages

Without pageCount the paginator shows the previous, the current and the next page, "next" is always enabled and there is no "last" button. Use it when the backend does not count the results.

Code
<script lang="ts">
	import { Paginator } from '@likable-hair/svelte';

	let page = $state(3);
</script>

<Paginator bind:page />

Compact

compact shows "3 / 12" between the arrows instead of the page numbers, for a card footer or a phone screen. Screen readers hear "Page 3 of 12" when the page changes.

Code
<script lang="ts">
	import { Paginator } from '@likable-hair/svelte';

	let page = $state(3);
</script>

<Paginator bind:page pageCount={12} compact />

More or fewer numbers

siblingCount sets how many pages appear on each side of the current one; showFirstLast={false} hides the buttons to the first and the last page, which are already reachable through the numbers.

Code
<script lang="ts">
	import { Paginator } from '@likable-hair/svelte';

	let page = $state(10);
</script>

<div class="rows">
	<Paginator bind:page pageCount={40} siblingCount={0} showFirstLast={false} />
	<Paginator bind:page pageCount={40} siblingCount={2} />
</div>

<style>
	.rows {
		display: flex;
		flex-direction: column;
		gap: 12px;
	}
</style>

Custom style

Every part has a CSS variable: here round buttons, the body font and a soft current page.

Code
<script lang="ts">
	import { Paginator } from '@likable-hair/svelte';

	let page = $state(2);
</script>

<Paginator
	bind:page
	pageCount={6}
	showFirstLast={false}
	--paginator-font-family="inherit"
	--paginator-button-size="34px"
	--paginator-button-border-radius="999px"
	--paginator-current-background="var(--global-color-primary-soft)"
	--paginator-current-color="var(--global-color-primary)"
	--paginator-current-box-shadow="none"
/>

Props

NameTypeDefaultDescription
page bindable numberCurrent page, from 1. Empty means 1.
pageCount numberNumber of pages. Without it the total is unknown: the previous, the current and the next page are shown, "next" is always enabled and there is no "last". Less than 1 counts as 1.
siblingCount number1Pages shown on each side of the current one, between the first and the last page.
showFirstLast booleantrueShows the buttons to the first and to the last page.
compact booleanfalseShows "7 / 24" between the arrows instead of the page numbers, for narrow spaces.
pageHref (page: number) => stringURL of a page. With it every control is a link, so the page can live in the URL and open in a new tab; a plain click still updates page and calls onchange.
locale stringBCP 47 locale of the accessible names: it and en are built in, other languages fall back to English. Defaults to the one set with setDefaultLocale, else en.
aria-label string | nullAccessible name of the <nav>. Defaults to "Pagination", in the language of locale.
firstLabel stringAccessible name of the first page button. Defaults to "First page", in the language of locale.
previousLabel stringAccessible name of the previous page button. Defaults to "Previous page", in the language of locale.
nextLabel stringAccessible name of the next page button. Defaults to "Next page", in the language of locale.
lastLabel stringAccessible name of the last page button. Defaults to "Last page", in the language of locale.
pageLabel stringAccessible name of every page number, where {page} is replaced by the number. Defaults to "Page {page}", in the language of locale.
statusLabel stringText read by screen readers in the compact look, where {page} and {count} are replaced by the current page and the number of pages. Defaults to "Page {page} of {count}", in the language of locale.
firstIcon stringFIRST_ICONSVG path of the first page icon.
previousIcon stringPREVIOUS_ICONSVG path of the previous page icon.
nextIcon stringNEXT_ICONSVG path of the next page icon.
lastIcon stringLAST_ICONSVG path of the last page icon.
class { container?: ClassValue; button?: ClassValue; current?: ClassValue; }{}Classes of the parts: container the root, button every arrow and page number, current the current page.
paginatorElement bindable HTMLElementThe root element.

Snippets

NameParametersDescription
pageSnippet{ page: number; current: boolean }Replaces the number inside every page button.

Events

NameTypeDescription
onchange(event: { page: number }) => voidCalled when the user picks another page, after page has changed. Not called for the current page.

CSS variables

For a single instance, pass them as style props: <Paginator --paginator-button-color="tomato">. The --paginator-default-* defaults apply to the whole app: override them in :root or in a theme.

Per-instance variableDefault
--paginator-gap
--paginator-default-gap 4px
--paginator-font-family
--paginator-default-font-family var(--global-font-family-mono)
--paginator-font-size
--paginator-default-font-size 13px
--paginator-icon-size
--paginator-default-icon-size 16px
--paginator-button-background
--paginator-default-button-background transparent
--paginator-button-size
--paginator-default-button-size 30px
--paginator-button-padding
--paginator-default-button-padding 0 8px
--paginator-button-border-radius
--paginator-default-button-border-radius var(--global-radius-sm)
--paginator-button-color
--paginator-default-button-color var(--global-color-text-2)
--paginator-button-font-weight
--paginator-default-button-font-weight 400
--paginator-duration
--paginator-default-duration var(--global-duration)
--paginator-easing
--paginator-default-easing var(--global-ease)
--paginator-button-hover-background
--paginator-default-button-hover-background var(--global-color-surface-2)
--paginator-button-hover-color
--paginator-default-button-hover-color var(--global-color-text)
--paginator-current-background
--paginator-default-current-background var(--global-fill-primary)
--paginator-current-box-shadow
--paginator-default-current-box-shadow var(--global-shadow-fill)
--paginator-current-color
--paginator-default-current-color var(--global-color-on-primary)
--paginator-current-font-weight
--paginator-default-current-font-weight 600
--paginator-focus-ring-width
--paginator-default-focus-ring-width var(--global-focus-ring-width)
--paginator-focus-ring-color
--paginator-default-focus-ring-color var(--global-focus-ring-color)
--paginator-focus-ring-offset
--paginator-default-focus-ring-offset var(--global-focus-ring-offset)
--paginator-disabled-opacity
--paginator-default-disabled-opacity 0.4
--paginator-ellipsis-padding
--paginator-default-ellipsis-padding 0 4px
--paginator-ellipsis-color
--paginator-default-ellipsis-color var(--global-color-text-3)
--paginator-status-padding
--paginator-default-status-padding 0 8px
--paginator-status-color
--paginator-default-status-color var(--global-color-text-2)