Block 101 of 297
Pagination
Previous, next and numbered page links with ellipses, built from the current page, page count and a URL pattern.
- Puck key
- PaginationBlock
- Export
- paginationBlock
- React component
- <Pagination />
- Path
- components/puck/pagination-block.tsx
- Dependencies
- None
- License
- MIT
About this block
When to use it, how to write for it, and what to change in the code.
What it's for
Previous and next links with numbered pages between them, generated from a current page number, a total and a URL pattern. Long ranges collapse into ellipses around the current page. On phones the numbers are replaced with a compact "Page 4 of 12" line between the two arrows.
- News and blog archives
- Long event listings or meeting archives split across pages
- Search results and directory listings
Writing the content
- Write the Page URL pattern with {page} where the number belongs, such as /news?page={page} or /news/page/{page}.
- Set First page link when page 1 lives at the plain URL, like /news, so you don't create a duplicate address.
- Choose 2 under Numbers around current only for long archives; 1 keeps the row short.
- The block hides itself when Total pages is less than 2, so it's safe to leave on templates.
Accessibility
- The whole control is a nav named from Navigation name. Give each one on a page a different name, such as "News pages".
- The current page has aria-current="page" as well as the filled indigo style, and each number has hidden "Page" text before it so it reads as "Page 5".
- At the first or last page, the unavailable Previous or Next link is marked aria-disabled and has no href, so it isn't a working link. Ellipses are hidden from screen readers.
Customizing the code
- The current page uses bg-indigo-600; change that class in the page link to rebrand.
- The ellipsis logic is in pageList. It shows a lone number instead of an ellipsis that would hide only one page.
Editor fields
What content editors see in the P1 sidebar when they select this block.
- Current pagenumber
- Total pagesnumber
- Page URL patterntext
- First page linktext
- Numbers around currentradio
- Previous texttext
- Next texttext
- Navigation nametext