pagination

Pagination with page navigation, next and previous links.

PreviousNext
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';

import { ZardPaginationImports } from '../pagination.imports';

@Component({
  selector: 'z-demo-pagination-preview',
  imports: [ZardPaginationImports],
  template: `
    <z-pagination [zTotal]="totalPages" [(zPageIndex)]="currentPage" [zContent]="content" />

    <ng-template #content>
      <ul z-pagination-content>
        <li z-pagination-item>
          <z-pagination-previous (click)="goToPrevious()" [zDisabled]="currentPage() === 1" />
        </li>

        @for (page of pages(); track page) {
          <li z-pagination-item>
            <button type="button" z-pagination-button [zActive]="page === currentPage()" (click)="goToPage(page)">
              <span class="sr-only">To page</span>
              {{ page }}
            </button>
          </li>
        }

        <li z-pagination-item>
          <z-pagination-ellipsis />
        </li>

        <li z-pagination-item>
          <z-pagination-next (click)="goToNext()" [zDisabled]="currentPage() === totalPages" />
        </li>
      </ul>
    </ng-template>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ZardDemoPaginationPreviewComponent {
  readonly totalPages = 3;
  readonly currentPage = signal(2);

  readonly pages = signal<number[]>(Array.from({ length: this.totalPages }, (_, i) => i + 1));

  goToPage(page: number) {
    this.currentPage.set(page);
  }

  goToPrevious() {
    if (this.currentPage() > 1) {
      this.currentPage.update(p => p - 1);
    }
  }

  goToNext() {
    if (this.currentPage() < this.totalPages) {
      this.currentPage.update(p => p + 1);
    }
  }
}

Installation

Copy
npx zard-cli@latest add pagination

Usage

import { ZardPaginationImports } from '@/shared/components/pagination/pagination.imports';
Copy
<z-pagination [zTotal]="100" [zPageSize]="10"></z-pagination>
Copy

Examples

Simple

A simple pagination with only page numbers.
import { ChangeDetectionStrategy, Component } from '@angular/core';

import { ZardPaginationImports } from '../pagination.imports';

@Component({
  selector: 'z-demo-pagination-simple',
  imports: [ZardPaginationImports],
  template: `
    <z-pagination [zTotal]="5" [(zPageIndex)]="currentPage" zSimple />
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ZardDemoPaginationSimpleComponent {
  protected currentPage = 2;
}

Icons Only

Use just the previous and next buttons without page numbers. This is useful for data tables with a rows per page selector.
import { ChangeDetectionStrategy, Component, computed, signal } from '@angular/core';

import { ZardFieldImports } from '@/shared/components/field';
import { ZardPaginationImports } from '@/shared/components/pagination';
import { ZardSelectImports } from '@/shared/components/select';

@Component({
  selector: 'z-demo-pagination-icons-only',
  imports: [ZardPaginationImports, ZardFieldImports, ZardSelectImports],
  template: `
    <div class="flex w-full justify-around">
      <div class="flex w-fit gap-4">
        <div z-field class="flex-row items-center">
          <label z-field-label for="select-rows-per-page" class="min-w-max">Rows Per Page</label>
          <z-select id="select-rows-per-page" zSize="sm" [(zValue)]="perPage" class="min-w-20">
            <z-select-item zValue="10">10</z-select-item>
            <z-select-item zValue="25">25</z-select-item>
            <z-select-item zValue="50">50</z-select-item>
            <z-select-item zValue="100">100</z-select-item>
          </z-select>
        </div>
        <z-pagination [zTotal]="totalPages()" [(zPageIndex)]="currentPage" [zContent]="content" />
      </div>
    </div>

    <ng-template #content>
      <ul z-pagination-content>
        <li z-pagination-item>
          <z-pagination-previous (click)="goToPrevious()" [zDisabled]="currentPage() === 1" />
        </li>

        <li z-pagination-item>
          <z-pagination-next (click)="goToNext()" [zDisabled]="currentPage() === totalPages()" />
        </li>
      </ul>
    </ng-template>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ZardDemoPaginationIconsOnlyComponent {
  private totalItems = 350;

  readonly currentPage = signal(1);
  readonly perPage = signal('25');
  readonly totalPages = computed(() => Math.ceil(this.totalItems / parseInt(this.perPage())));

  goToPrevious() {
    if (this.currentPage() > 1) {
      this.currentPage.update(p => p - 1);
    }
  }

  goToNext() {
    if (this.currentPage() < this.totalPages()) {
      this.currentPage.update(p => p + 1);
    }
  }
}

Routing

Wire a[z-pagination-button] to Angular RouterLink with [queryParams] and queryParamsHandling="merge" so page links drive real router navigation — the URL updates and the page is bookmarkable, with no full reload.
import { ChangeDetectionStrategy, Component, computed, inject } from '@angular/core';
import { toSignal } from '@angular/core/rxjs-interop';
import { ActivatedRoute, RouterLink } from '@angular/router';

import { NgIcon, provideIcons } from '@ng-icons/core';
import { lucideChevronLeft, lucideChevronRight } from '@ng-icons/lucide';

import { paginationNextVariants, paginationPreviousVariants } from '@/shared/components/pagination/pagination.variants';

import { ZardPaginationImports } from '../pagination.imports';

@Component({
  selector: 'z-demo-pagination-routing',
  imports: [ZardPaginationImports, RouterLink, NgIcon],
  template: `
    <z-pagination
      zAriaLabel="Routing pagination"
      [zTotal]="totalPages"
      [zPageIndex]="currentPage()"
      [zContent]="content"
    />

    <ng-template #content>
      <ul z-pagination-content>
        <li z-pagination-item>
          <a
            z-pagination-button
            zSize="default"
            [class]="previousClasses"
            [zDisabled]="currentPage() === 1"
            [routerLink]="currentPage() === 1 ? null : []"
            [queryParams]="{ page: previousPage() }"
            queryParamsHandling="merge"
            [attr.aria-disabled]="currentPage() === 1 ? 'true' : null"
          >
            <span class="sr-only">Go to previous page</span>
            <ng-icon name="lucideChevronLeft" aria-hidden="true" />
            <span class="hidden sm:block" aria-hidden="true">Previous</span>
          </a>
        </li>

        @for (page of pages; track page) {
          <li z-pagination-item>
            <a
              z-pagination-button
              [routerLink]="[]"
              [queryParams]="{ page }"
              queryParamsHandling="merge"
              [zActive]="page === currentPage()"
              [attr.aria-current]="page === currentPage() ? 'page' : null"
            >
              <span class="sr-only">To page</span>
              {{ page }}
            </a>
          </li>
        }

        <li z-pagination-item>
          <a
            z-pagination-button
            zSize="default"
            [class]="nextClasses"
            [zDisabled]="currentPage() === totalPages"
            [routerLink]="currentPage() === totalPages ? null : []"
            [queryParams]="{ page: nextPage() }"
            queryParamsHandling="merge"
            [attr.aria-disabled]="currentPage() === totalPages ? 'true' : null"
          >
            <span class="sr-only">Go to next page</span>
            <span class="hidden sm:block" aria-hidden="true">Next</span>
            <ng-icon name="lucideChevronRight" aria-hidden="true" />
          </a>
        </li>
      </ul>
    </ng-template>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
  viewProviders: [provideIcons({ lucideChevronLeft, lucideChevronRight })],
})
export class ZardDemoPaginationRoutingComponent {
  private readonly route = inject(ActivatedRoute);

  protected readonly totalPages = 5;
  protected readonly pages = Array.from({ length: this.totalPages }, (_, i) => i + 1);
  protected readonly previousClasses = paginationPreviousVariants();
  protected readonly nextClasses = paginationNextVariants();

  private readonly queryParamMap = toSignal(this.route.queryParamMap, {
    initialValue: this.route.snapshot.queryParamMap,
  });

  protected readonly currentPage = computed(() => {
    const page = Number(this.queryParamMap().get('page'));
    return Number.isInteger(page) && page >= 1 && page <= this.totalPages ? page : 1;
  });

  protected readonly previousPage = computed(() => Math.max(1, this.currentPage() - 1));
  protected readonly nextPage = computed(() => Math.min(this.totalPages, this.currentPage() + 1));
}

RTL

To enable RTL support in zard/ui, see the RTL configuration guide.
// You will notice this example is rendered inside a wrapper that sets the dir and data-lang attributes, and
// reads its text from a translations helper. This is because this site is not RTL by default.
// In your application you won't need either: set dir="rtl" on <html> (or use the CDK Dir directive on a subtree)
// and write the text of your own language. See the RTL guide: https://zardui.com/docs/rtl

import { ChangeDetectionStrategy, Component, signal } from '@angular/core';

import { injectRtlTranslation, type ZardRtlTranslations } from '@/shared/demo-utils/rtl-translation';

import { ZardPaginationImports } from '../pagination.imports';

const translations: ZardRtlTranslations<{ previous: string; next: string }> = {
  en: {
    dir: 'ltr',
    values: {
      previous: 'Previous',
      next: 'Next',
    },
  },
  ar: {
    dir: 'rtl',
    values: {
      previous: 'السابق',
      next: 'التالي',
    },
  },
  he: {
    dir: 'rtl',
    values: {
      previous: 'הקודם',
      next: 'הבא',
    },
  },
};

@Component({
  selector: 'z-demo-pagination-rtl',
  imports: [...ZardPaginationImports],
  template: `
    <z-pagination [zTotal]="3" [(zPageIndex)]="currentPage" [zContent]="content" />

    <ng-template #content>
      <ul z-pagination-content>
        <li z-pagination-item>
          <z-pagination-previous
            [zText]="i18n.t().previous"
            [zDisabled]="currentPage() === 1"
            (click)="go(currentPage() - 1)"
          />
        </li>

        @for (page of pages; track page) {
          <li z-pagination-item>
            <button type="button" z-pagination-button [zActive]="page === currentPage()" (click)="go(page)">
              {{ page }}
            </button>
          </li>
        }

        <li z-pagination-item>
          <z-pagination-ellipsis />
        </li>

        <li z-pagination-item>
          <z-pagination-next
            [zText]="i18n.t().next"
            [zDisabled]="currentPage() === 3"
            (click)="go(currentPage() + 1)"
          />
        </li>
      </ul>
    </ng-template>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ZardDemoPaginationRtlComponent {
  protected readonly i18n = injectRtlTranslation(translations);

  protected readonly pages = [1, 2, 3];
  protected readonly currentPage = signal(2);

  protected go(page: number) {
    if (page >= 1 && page <= 3) {
      this.currentPage.set(page);
    }
  }
}

API Reference

z-pagination

Full pagination from [zTotal] and [(zPageIndex)], or custom markup via [zContent].

Prop
[class]

Custom CSS classes

Type
string
Default
''
[zAriaLabel]

Accessible name

Type
string
Default
'Pagination'
[zContent]

Custom markup; the root then ignores its other inputs

Type
TemplateRef<void> | undefined
Default
—
[zDisabled]

Disables pagination interaction

Type
boolean
Default
false
[zNextText]

Label of the next button

Type
string
Default
'Next'
[zPreviousText]

Label of the previous button

Type
string
Default
'Previous'
[zPageIndex]

Current page

Type
number
Default
1
[(zPageIndex)]

Current page index

Type
number
Default
1
[zSimple]

Shows only page numbers

Type
boolean
Default
false
[zSize]

Size of the page buttons

Type
'icon' | 'icon-xs' | 'icon-sm' | 'icon-lg'
Default
'icon'
[zTotal]

Total number of pages

Type
number
Default
1

ul[z-pagination-content]

List that holds the pagination items.

Prop
[class]

Custom CSS classes

Type
string
Default
''

li[z-pagination-item]

List item wrapping a button or ellipsis.

button[z-pagination-button]

A page button; also works as a[z-pagination-button] with routerLink.

Prop
[class]

Custom CSS classes

Type
string
Default
''
[zActive]

Marks the current page

Type
boolean
Default
false
[zDisabled]

Disables the button

Type
boolean
Default
false
[zSize]

Button size

Type
'default' | 'xs' | 'sm' | 'lg' | 'icon' | 'icon-xs' | 'icon-sm' | 'icon-lg'
Default
'icon'

z-pagination-previous

Previous-page button; the chevron flips in RTL.

Prop
[class]

Custom CSS classes

Type
string
Default
''
[zDisabled]

Disables the button

Type
boolean
Default
false
[zSize]

Button size

Type
'default' | 'xs' | 'sm' | 'lg'
Default
'default'
[zText]

Visible label

Type
string
Default
'Previous'

z-pagination-next

Next-page button; the chevron flips in RTL.

Prop
[class]

Custom CSS classes

Type
string
Default
''
[zDisabled]

Disables the button

Type
boolean
Default
false
[zSize]

Button size

Type
'default' | 'xs' | 'sm' | 'lg'
Default
'default'
[zText]

Visible label

Type
string
Default
'Next'

z-pagination-ellipsis

Ellipsis for omitted pages.

Prop
[class]

Custom CSS classes

Type
string
Default
''
github iconwhatsapp icondiscord iconX icon

Made with ❤ in Brazil. Open source and available on GitHub .