Alert

A callout for something to notice — a success, a warning, an error — with an icon, a title, a description and an action. In the look of the app's style.

FeedbackExperimental

Usage

import { Component, ViewEncapsulation } from '@angular/core';import {  ScAlert,  ScAlertDescription,  ScAlertTitle,} from '@semantic-components/ui';import { SiCircleCheckIcon, SiInfoIcon } from '@semantic-icons/lucide-icons';
@Component({  selector: 'app-alert-usage-demo',  imports: [    ScAlert,    ScAlertDescription,    ScAlertTitle,    SiCircleCheckIcon,    SiInfoIcon,  ],  template: `    <div class="grid w-full max-w-md items-start gap-4">      <div scAlert>        <svg siCircleCheckIcon></svg>        <div scAlertTitle>Payment successful</div>        <div scAlertDescription>          Your payment of $29.99 has been processed. A receipt has been sent to          your email address.        </div>      </div>      <div scAlert>        <svg siInfoIcon></svg>        <div scAlertTitle>New feature available</div>        <div scAlertDescription>          We&apos;ve added dark mode support. You can enable it in your account          settings.        </div>      </div>    </div>  `,  host: { class: 'flex w-full justify-center' },  encapsulation: ViewEncapsulation.None,})export class AlertUsageDemo {}

Anatomy

Every part is a directive on your element; the icon is yours, the first child: it sits beside the title and the description.

import {  ScAlert, ScAlertTitle, ScAlertDescription, ScAlertAction,} from '@semantic-components/ui';
<div scAlert>  <svg></svg>  <div scAlertTitle>…</div>  <div scAlertDescription>…</div>  <div scAlertAction>…</div></div>

Announcing

An alert has no role of its own: one that is on the page when it loads is read in its place, like the rest of the page. Announce one only when it appears after something the user did — a save, an error:

  • role="status" — polite: read when the screen reader is free. For most: saved, sent, updated.
  • role="alert" — urgent: interrupts what is being read. Only for what needs action now: a failed payment, a lost connection.
  • Put the role on a wrapper that is on the page from the start, empty, and show the alert inside it. Screen readers watch a live region that already exists and announce what changes in it; with the role on an alert added by @if, the region and its text arrive together, and many (NVDA, JAWS, VoiceOver, depending on the browser) start watching too late and say nothing.
  • role="alert" is more forgiving: browsers send an event when one is inserted, so on the alert itself it is usually read. role="status" has no such event — the wrapper is the safe way for both.
  • The other way, without a wrapper: keep the alert always rendered with its role and change only its text. But an empty alert box stays on the page until there is something to say; the wrapper has no look, so nothing shows until then.
  • Don't give a role to an alert that is there from the start: it would be announced on every visit, or not at all.

The Announced example shows it.

Examples

Basic

Account updated successfully
Your profile information has been saved. Changes will be reflected immediately.
import { Component, ViewEncapsulation } from '@angular/core';import {  ScAlert,  ScAlertDescription,  ScAlertTitle,} from '@semantic-components/ui';import { SiCircleCheckIcon } from '@semantic-icons/lucide-icons';
/** An icon, a title, a description: the icon beside both. */@Component({

Destructive

Payment failed
Your payment could not be processed. Please check your payment method and try again.
import { Component, ViewEncapsulation } from '@angular/core';import {  ScAlert,  ScAlertDescription,  ScAlertTitle,} from '@semantic-components/ui';import { SiCircleAlertIcon } from '@semantic-icons/lucide-icons';
@Component({  selector: 'app-destructive-alert-demo',

Success and warning

Account verified
Your email address is confirmed. You can now publish projects.
Storage almost full
You have used 90% of your storage. Remove files or upgrade your plan.
import { Component, ViewEncapsulation } from '@angular/core';import {  ScAlert,  ScAlertDescription,  ScAlertTitle,} from '@semantic-components/ui';import {  SiCircleCheckIcon,  SiTriangleAlertIcon,} from '@semantic-icons/lucide-icons';

Action

Dark mode is now available
Enable it under your profile settings to get started.
import { Component, ViewEncapsulation } from '@angular/core';import {  ScAlert,  ScAlertAction,  ScAlertDescription,  ScAlertTitle,  ScButton,} from '@semantic-components/ui';
/** A button in the alert's corner; the text keeps clear of it. */

Custom 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 { Component, ViewEncapsulation } from '@angular/core';import {  ScAlert,  ScAlertDescription,  ScAlertTitle,} from '@semantic-components/ui';import { SiTriangleAlertIcon } from '@semantic-icons/lucide-icons';
/** Your own colors: classes over the style's (cn: a later class wins). */@Component({

Announced

import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScAlert,  ScAlertDescription,  ScAlertTitle,  ScButton,} from '@semantic-components/ui';import { SiCircleCheckIcon } from '@semantic-icons/lucide-icons';
/**

RTL

تم تحديث الحساب بنجاح
تم حفظ معلومات ملفك الشخصي. ستظهر التغييرات على الفور.
الوضع الداكن متاح الآن
فعّله من إعدادات ملفك الشخصي للبدء.
import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation } from '@angular/core';import {  ScAlert,  ScAlertAction,  ScAlertDescription,  ScAlertTitle,  ScButton,} from '@semantic-components/ui';import { SiCircleCheckIcon } from '@semantic-icons/lucide-icons';

API reference

Each part takes class, merged over the style (cn: a later class wins).

PartSelectorDescription
ScAlertdiv[scAlert] The alert; no role (see Announcing). Input variant: 'default', 'destructive', 'success' or 'warning' (the last two not shadcn's: the toast's colours).
ScAlertTitle[scAlertTitle] The title, beside the icon.
ScAlertDescription[scAlertDescription] Muted text under the title; its links underlined.
ScAlertAction[scAlertAction] A button in the end corner; the text keeps clear of it.