Pagination
Links to move between pages of results. Same markup and props in every style: switch the style in the header to see it change.
Basic
Arrows, the first and last page, and the pages around this one. Gaps show an ellipsis.
<nav class="vin-pagination" aria-label="Pagination">
<ul class="vin-pagination__list">
<li><a class="vin-btn vin-btn--ghost vin-btn--icon" href="#" aria-label="Previous page"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m15 6-6 6 6 6"/></svg></a></li>
<li><a class="vin-btn vin-btn--ghost vin-pagination__page" href="#">1</a></li>
<li><a class="vin-btn vin-btn--outline vin-pagination__page" href="#" aria-current="page">2</a></li>
<li><a class="vin-btn vin-btn--ghost vin-pagination__page" href="#">3</a></li>
<li><span class="vin-pagination__ellipsis" aria-hidden="true">…</span></li>
<li><a class="vin-btn vin-btn--ghost vin-pagination__page" href="#">10</a></li>
<li><a class="vin-btn vin-btn--ghost vin-btn--icon" href="#" aria-label="Next page"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m9 6 6 6-6 6"/></svg></a></li>
</ul>
</nav>import { Pagination } from "@/components/vin/pagination";
export function PaginationBasic() {
return <Pagination page={2} count={10} href={(p) => `?page=${p}`} />;
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Pagination from "@/components/vin/pagination.vue";
</script>
<template>
<Pagination :page="2" :count="10" :href="(p: number) => `?page=${p}`" />
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Pagination from "$lib/components/vin/pagination.svelte";
</script>
<Pagination page={2} count={10} href={(p) => `?page=${p}`} />With labels
"Previous" and "Next" as words. At the first page, Previous is disabled.
<nav class="vin-pagination" aria-label="Pagination">
<ul class="vin-pagination__list">
<li><a class="vin-btn vin-btn--ghost" role="link" aria-disabled="true"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m15 6-6 6 6 6"/></svg> Previous</a></li>
<li><a class="vin-btn vin-btn--outline vin-pagination__page" href="#" aria-current="page">1</a></li>
<li><a class="vin-btn vin-btn--ghost vin-pagination__page" href="#">2</a></li>
<li><a class="vin-btn vin-btn--ghost vin-pagination__page" href="#">3</a></li>
<li><a class="vin-btn vin-btn--ghost" href="#">Next <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m9 6 6 6-6 6"/></svg></a></li>
</ul>
</nav>import { Pagination } from "@/components/vin/pagination";
export function PaginationLabels() {
return <Pagination page={1} count={3} labels href={(p) => `?page=${p}`} />;
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Pagination from "@/components/vin/pagination.vue";
</script>
<template>
<Pagination :page="1" :count="3" labels :href="(p: number) => `?page=${p}`" />
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Pagination from "$lib/components/vin/pagination.svelte";
</script>
<Pagination page={1} count={3} labels href={(p) => `?page=${p}`} />Simple
Just Previous and Next with the page count, for phones and feeds.
<nav class="vin-pagination" aria-label="Pagination">
<ul class="vin-pagination__list">
<li><a class="vin-btn vin-btn--outline vin-btn--sm" href="#"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m15 6-6 6 6 6"/></svg> Previous</a></li>
<li><span class="vin-pagination__status">Page 2 of 10</span></li>
<li><a class="vin-btn vin-btn--outline vin-btn--sm" href="#">Next <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m9 6 6 6-6 6"/></svg></a></li>
</ul>
</nav>import { Pagination } from "@/components/vin/pagination";
export function PaginationSimple() {
return <Pagination page={2} count={10} simple href={(p) => `?page=${p}`} />;
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Pagination from "@/components/vin/pagination.vue";
</script>
<template>
<Pagination :page="2" :count="10" simple :href="(p: number) => `?page=${p}`" />
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Pagination from "$lib/components/vin/pagination.svelte";
</script>
<Pagination page={2} count={10} simple href={(p) => `?page=${p}`} />Installation
React, Vue and Svelte: add the component to your project with the CLI. It reads your framework from vin.json and also copies any component this one needs. Then import it:
npx @vinish/ui add paginationimport { Pagination, pageRange } from "@/components/vin/pagination";import Pagination, { pageRange } from "@/components/vin/pagination.vue";import Pagination, { pageRange } from "$lib/components/vin/pagination.svelte";The import paths assume the default folders: @/components/vin (React and Vue, with the usual @ → src alias) and $lib/components/vin (SvelteKit). Use your own if you chose another folder in init. How the Vue and Svelte versions pass values and content is in Frameworks.
Plain HTML: the classes come with the style's stylesheet. It needs no JavaScript.
API
From spec/pagination.json, which every framework version is tested against.
| Prop | Values | Default | In HTML |
|---|---|---|---|
pageThis page (1-based). | number | — | aria-current="page" and .vin-btn--outline on its link |
countHow many pages there are. | number | — | — |
hrefLink for a page. Without it, pages are buttons and onPageChange is called. | (page: number) => string | — | — |
onPageChange | (page: number) => void | — | — |
siblingsPages shown each side of this one before an ellipsis. | number | 1 | — |
labelsShow "Previous" and "Next" as words, not only arrows. | boolean | false | — |
simplePrevious, "Page 2 of 10", Next — no page numbers. | boolean | false | .vin-pagination__status |
Parts
| React, Vue, Svelte | HTML classes |
|---|---|
<Pagination> | .vin-pagination.vin-pagination__list.vin-pagination__page.vin-pagination__ellipsis.vin-pagination__status |
Accessibility
- A <nav> named "Pagination" with a list of links.
- This page has aria-current="page"; screen readers say "current page".
- Arrow-only links have an aria-label ("Previous page", "Next page").
- At the first or last page the link is disabled with aria-disabled="true" and no href, so it can't be followed or focused.
- Every page link is at least 36 by 36 pixels.
Customize
Saved in this browser. Style and accent are in the header.