alert

Displays a callout for user attention.

PreviousNext
Success! Your changes have been saved
This is an alert with icon, title and description.
Unable to process your payment
Please verify your billing information and try again.
import { ChangeDetectionStrategy, Component } from '@angular/core';

import { provideIcons } from '@ng-icons/core';
import { lucideCircleCheck } from '@ng-icons/lucide';

import { ZardAlertComponent } from '@/shared/components/alert/alert.component';

@Component({
  selector: 'z-demo-alert-preview',
  imports: [ZardAlertComponent],
  template: `
    <div class="grid w-full max-w-md items-start gap-4">
      <z-alert
        zIcon="lucideCircleCheck"
        zTitle="Success! Your changes have been saved"
        zDescription="This is an alert with icon, title and description."
      />

      <z-alert
        zType="destructive"
        zTitle="Unable to process your payment"
        zDescription="Please verify your billing information and try again."
      />
    </div>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
  viewProviders: [provideIcons({ lucideCircleCheck })],
})
export class ZardDemoAlertPreviewComponent {}

Installation

Copy
npx zard-cli@latest add alert

Usage

import { ZardAlertComponent } from '@/shared/components/alert/alert.component';
Copy
<z-alert zTitle="Heads up!" zDescription="You can add components to your app using the cli."></z-alert>
Copy

Examples

basic

Use zIcon, zTitle, and zDescription on z-alert to render a callout with an icon, title, and description.
Payment successful
Your payment of $29.99 has been processed. A receipt has been sent to your email address.
New feature available
We've added dark mode support. You can enable it in your account settings.
import { ChangeDetectionStrategy, Component } from '@angular/core';

import { provideIcons } from '@ng-icons/core';
import { lucideCircleCheck, lucideInfo } from '@ng-icons/lucide';

import { ZardAlertComponent } from '@/shared/components/alert/alert.component';

@Component({
  selector: 'z-demo-alert-basic',
  imports: [ZardAlertComponent],
  template: `
    <div class="grid w-full max-w-md items-start gap-4">
      <z-alert
        zIcon="lucideCircleCheck"
        zTitle="Payment successful"
        zDescription="Your payment of $29.99 has been processed. A receipt has been sent to your email address."
      />

      <z-alert
        zIcon="lucideInfo"
        zTitle="New feature available"
        zDescription="We've added dark mode support. You can enable it in your account settings."
      />
    </div>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
  viewProviders: [provideIcons({ lucideCircleCheck, lucideInfo })],
})
export class ZardDemoAlertBasicComponent {}

destructive

Set zType="destructive" on z-alert to flag a critical message. When zIcon is not set, it defaults to lucideCircleAlert.
Payment failed
Your payment could not be processed. Please check your payment method and try again.
import { ChangeDetectionStrategy, Component } from '@angular/core';

import { ZardAlertComponent } from '@/shared/components/alert/alert.component';

@Component({
  selector: 'z-demo-alert-destructive',
  imports: [ZardAlertComponent],
  template: `
    <div class="grid w-full max-w-md items-start gap-4">
      <z-alert
        zType="destructive"
        zTitle="Payment failed"
        zDescription="Your payment could not be processed. Please check your payment method and try again."
      />
    </div>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ZardDemoAlertDestructiveComponent {}

action

Pass a TemplateRef to zAction to render a z-button inside the alert.
Dark mode is now available
Enable it under your profile settings to get started.
import { ChangeDetectionStrategy, Component } from '@angular/core';

import { ZardAlertComponent } from '@/shared/components/alert/alert.component';
import { ZardButtonComponent } from '@/shared/components/button';

@Component({
  selector: 'z-demo-alert-action',
  imports: [ZardAlertComponent, ZardButtonComponent],
  template: `
    <ng-template #actionTpl>
      <button type="button" z-button zSize="xs">Enable</button>
    </ng-template>

    <div class="grid w-full max-w-md items-start gap-4">
      <z-alert
        class="w-md"
        zTitle="Dark mode is now available"
        zDescription="Enable it under your profile settings to get started."
        [zAction]="actionTpl"
      />
    </div>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ZardDemoAlertActionComponent {}

custom colors

Override the class input on z-alert to customize its border, background, and text colors.
Your subscription will expire in 3 days
Renew now to avoid service interruption or upgrade to a paid plan to continue using the service.
import { ChangeDetectionStrategy, Component } from '@angular/core';

import { provideIcons } from '@ng-icons/core';
import { lucideAlertTriangle } from '@ng-icons/lucide';

import { ZardAlertComponent } from '@/shared/components/alert/alert.component';

@Component({
  selector: 'z-demo-alert-custom-colors',
  imports: [ZardAlertComponent],
  template: `
    <div class="grid w-full max-w-md items-start gap-4">
      <z-alert
        class="max-w-md border-amber-200 bg-amber-50 text-amber-900 dark:border-amber-900 dark:bg-amber-950 dark:text-amber-50"
        zDescription="Renew now to avoid service interruption or upgrade to a paid plan to continue using the service."
        zIcon="lucideAlertTriangle"
        zTitle="Your subscription will expire in 3 days"
      />
    </div>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
  viewProviders: [provideIcons({ lucideAlertTriangle })],
})
export class ZardDemoAlertCustomColorsComponent {}

rtl

To enable RTL support in zard/ui, see the RTL configuration guide.
تم الدفع بنجاح
تمت معالجة دفعتك البالغة 29.99 دولارًا. تم إرسال إيصال إلى عنوان بريدك الإلكتروني.
ميزة جديدة متاحة
لقد أضفنا دعم الوضع الداكن. يمكنك تفعيله في إعدادات حسابك.
// 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 } from '@angular/core';

import { provideIcons } from '@ng-icons/core';
import { lucideCircleCheck, lucideInfo } from '@ng-icons/lucide';

import { ZardAlertComponent } from '@/shared/components/alert/alert.component';
import { ZardButtonComponent } from '@/shared/components/button/button.component';
import { injectRtlTranslation, type ZardRtlTranslations } from '@/shared/demo-utils/rtl-translation';

interface AlertRtlValues {
  paymentTitle: string;
  paymentDescription: string;
  featureTitle: string;
  featureDescription: string;
  enable: string;
}

const translations: ZardRtlTranslations<AlertRtlValues> = {
  en: {
    dir: 'ltr',
    values: {
      paymentTitle: 'Payment successful',
      paymentDescription: 'Your payment of $29.99 has been processed. A receipt has been sent to your email address.',
      featureTitle: 'New feature available',
      featureDescription: "We've added dark mode support. You can enable it in your account settings.",
      enable: 'Enable',
    },
  },
  ar: {
    dir: 'rtl',
    values: {
      paymentTitle: 'تم الدفع بنجاح',
      paymentDescription: 'تمت معالجة دفعتك البالغة 29.99 دولارًا. تم إرسال إيصال إلى عنوان بريدك الإلكتروني.',
      featureTitle: 'ميزة جديدة متاحة',
      featureDescription: 'لقد أضفنا دعم الوضع الداكن. يمكنك تفعيله في إعدادات حسابك.',
      enable: 'تفعيل',
    },
  },
  he: {
    dir: 'rtl',
    values: {
      paymentTitle: 'התשלום בוצע בהצלחה',
      paymentDescription: 'התשלום שלך בסך 29.99 דולר עובד. קבלה נשלחה לכתובת האימייל שלך.',
      featureTitle: 'תכונה חדשה זמינה',
      featureDescription: 'הוספנו תמיכה במצב כהה. אתה יכול להפעיל אותו בהגדרות החשבון שלך.',
      enable: 'הפעל',
    },
  },
};

@Component({
  selector: 'z-demo-alert-rtl',
  imports: [ZardAlertComponent, ZardButtonComponent],
  template: `
    <ng-template #actionTpl>
      <button type="button" z-button zSize="xs">{{ i18n.t().enable }}</button>
    </ng-template>

    <div class="grid w-full max-w-md items-start gap-4">
      <z-alert
        zIcon="lucideCircleCheck"
        [zTitle]="i18n.t().paymentTitle"
        [zDescription]="i18n.t().paymentDescription"
      />

      <z-alert
        zIcon="lucideInfo"
        [zTitle]="i18n.t().featureTitle"
        [zDescription]="i18n.t().featureDescription"
        [zAction]="actionTpl"
      />
    </div>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
  viewProviders: [provideIcons({ lucideCircleCheck, lucideInfo })],
})
export class ZardDemoAlertRtlComponent {
  protected readonly i18n = injectRtlTranslation(translations);
}

API Reference

z-alertComponent

Displays a callout for user attention.

PropertyDescriptionTypeDefault
[class] Custom CSS classes ClassValue ''
[zAction] Alert action TemplateRef<void> -
[zDescription] Alert description string | TemplateRef<void> -
[zIcon] Alert icon (an ng-icons name or a TemplateRef). When unset, defaults to 'lucideCircleAlert' for the 'destructive' zType; otherwise no icon renders. TemplateRef<void> | string -
[zRole] Overrides the ARIA role. Defaults to 'status' when [zAction] is set, otherwise 'alert'. 'alert' | 'status' -
[zTitle] Alert title string | TemplateRef<void> -
[zType] Alert variant 'default' | 'destructive' 'default'
github iconwhatsapp icondiscord iconX icon

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