Skip to content
Alpha

Hololink UI is under active development. Components, APIs and these docs may change without notice.

Holo Pagination

<holo-pagination> renders a nav landmark labelled “Pagination” with Previous/Next controls and a truncated list of page number buttons (collapsed with an ellipsis for large page counts). The current page is marked with aria-current="page", and the Previous/Next controls are disabled at the bounds.

Use it for:

  • Moving between pages of a long, ordered set of results where the user knows the page count.
  • Search results, tables and article lists split over several pages.

Don’t use it for:

  • Showing the user’s position in a site hierarchy. Use Breadcrumb.
  • Moving through the steps of a form. Show step state in your own wizard UI.
  • Infinite lists loaded on scroll. Provide a “Load more” Button.
<holo-pagination page="1" total-pages="5"></holo-pagination>
<holo-pagination page="10" total-pages="20" sibling-count="1"></holo-pagination>

Set href-template to render every control as a real link. {page} is replaced with each page number.

<holo-pagination page="2" total-pages="5" href-template="?page={page}"></holo-pagination>
  • Button mode (default): controls are <button>s. Use it for client-side paging. holoPageChange is emitted and preventDefault() has no effect.
  • Link mode (href-template set): controls are <a href>. Use it when each page is its own URL, so users can open pages in a new tab and copy the address. The current page keeps its href, Previous/Next carry rel="prev" and rel="next", and at the bounds they render as disabled links with no href.

In link mode a plain click emits holoPageChange and then follows the link. Ctrl, Cmd, Shift or Alt clicks and middle-clicks are left to the browser and emit nothing. Clicking the current page does nothing. The template is passed through unchanged, so it must be author-controlled and never built from untrusted input. URL-encoding is up to you. Page 1 cannot be given a different canonical URL (for example /blog instead of /blog/page/1); use a server redirect or rel="canonical".

Call preventDefault() on holoPageChange to cancel the link navigation and route yourself. The links sit in shadow DOM, so global link interceptors that look for event.target.closest('a') will not see them.

pagination.addEventListener('holoPageChange', event => {
event.preventDefault();
router.push(`/results?page=${event.detail}`);
});

The component has already set page to event.detail when holoPageChange fires, even if you cancel it. If your router rejects or aborts the navigation, set page back to the page you actually show.

pagination.addEventListener('holoPageChange', async event => {
event.preventDefault();
const previous = pagination.page;
try {
await router.push(`/results?page=${event.detail}`);
} catch {
pagination.page = previous;
}
});

The links only exist once the component has loaded. For crawlers and users without JavaScript, put plain links inside the element. The component has no <slot>, so after upgrade they are not rendered.

<holo-pagination page="2" total-pages="3" href-template="?page={page}">
<a href="?page=1">1</a>
<a href="?page=2">2</a>
<a href="?page=3">3</a>
</holo-pagination>

The component renders a <nav> named by label (default “Pagination”) containing a <ul>. In button mode every control is a native <button type="button">; in link mode every control is a native <a href>. Page controls are named from pageLabel (default Page {page}, where {page} is replaced with the number) and the current one has aria-current="page". The previous and next buttons are named by previousLabel and nextLabel (default “Previous page” and “Next page”). At the first or last page the bound control is disabled. In button mode it is natively disabled (and sets aria-disabled="true"). In link mode it renders as <a role="link" aria-disabled="true"> with no href, so it is not focusable. Link-mode controls intentionally look the same as button-mode controls. Ellipses are aria-hidden.

Key Action
Tab Moves between the previous, page and next controls
Enter, Space Goes to the focused page. In link mode only Enter works; Space scrolls.
  • There is no roving tabindex. Each control is a tab stop, except disabled bounds in link mode, which have no href and are skipped.
  • The focus ring is shown with :focus-visible.
  • The component emits holoPageChange but does not announce the new page. That is your job. It only keeps focus from being lost: if the focused control is removed or disabled (for example Next on the last page), focus moves to the current-page control. On narrow containers the controls wrap onto more rows rather than scrolling sideways.

You provide:

  • A change that is perceivable after navigation: update the heading or a live region, or move focus to the start of the new content.
  • A distinct label if there are several pagination controls on one page, and translated label, previous-label, next-label and page-label for other languages.

Importing

import '@philbob/hololink-ui/holo-pagination';

Properties

PropertyAttributeTypeDefaultDescription
hrefTemplatehref-templatestring | undefined—Turns the controls into links. {page} is replaced with each page number, for example ?page={page}. The template is passed through unchanged, so it must come from the author, not from untrusted input. Leave unset for button mode.
labellabelstring'Pagination'The accessible name of the navigation landmark. Give each pagination on a page a distinct label.
nextLabelnext-labelstring'Next page'The accessible name of the next-page button.
pagepagenumber1The current page (1-indexed). Updated when the user navigates.
pageLabelpage-labelstring'Page {page}'The accessible name of each page button. {page} is replaced with the page number.
previousLabelprevious-labelstring'Previous page'The accessible name of the previous-page button.
siblingCountsibling-countnumber1How many page numbers to show on either side of the current page.
totalPagestotal-pagesnumber1The total number of pages.

Events

EventDetailDescription
holoPageChangenumberEmitted when the user navigates to a different page. detail is the new page number. In link mode it fires only for a plain click, and calling preventDefault() on it cancels the link navigation so you can route client-side. In button mode preventDefault() has no effect.

CSS custom properties

PropertyDescription
--holo-pagination-current-bgBackground color of the current page button.
--holo-pagination-current-text-colorText color of the current page button.
--holo-pagination-gapSpace between pagination buttons.
--holo-pagination-text-colorText color of page buttons.