Shows important information on a page. Can contain a hint, signal a status change, or indicate a problem.

Alerts come in two sizes. The normal size is the default; pass [compact]="true" for the denser compact size used in tight spaces such as popovers and forms.

Heading
If there is no heading, do not put a period at the end of the last sentence. If the message contains both body text and a heading, put a period at the end of the body text.
Heading
If there is no heading, do not put a period at the end of the last sentence. If the message contains both body text and a heading, put a period at the end of the body text.

By default, alerts are styled conservatively and stand out only by the icon color. If the block gets lost on screen, you can draw attention to it using the colored background variant.

Default
If there is no heading, do not put a period at the end of the last sentence. If the message contains both body text and a heading, put a period at the end of the body text.
Colored
If there is no heading, do not put a period at the end of the last sentence. If the message contains both body text and a heading, put a period at the end of the body text.

The alertColor input sets the status: error, warning, success or info (the default). It drives the background in the colored variant and auto-tints a projected status icon that has no explicit [color]: the icon is tinted to the matching status color, except info, which is tinted to contrast. Set [color] on the icon yourself to opt out of the auto-tint.

Project a single status icon. The slot renders every [kbq-icon] and [kbq-icon-item] it receives but auto-tints only one of them — a kbq-icon wins over a kbq-icon-item — so any further icon keeps whatever color it was given. Projecting one of each also logs a warning in dev mode.

Information
If there is no heading, do not put a period at the end of the last sentence. If the message contains both body text and a heading, put a period at the end of the body text.
Warning
If there is no heading, do not put a period at the end of the last sentence. If the message contains both body text and a heading, put a period at the end of the body text.
Error
If there is no heading, do not put a period at the end of the last sentence. If the message contains both body text and a heading, put a period at the end of the body text.
Success
If there is no heading, do not put a period at the end of the last sentence. If the message contains both body text and a heading, put a period at the end of the body text.

The block can be hidden by clicking the icon button in the corner of the alert. The alert does not hide itself — listen to the (closed) output (emitted when the close control is activated) and remove or hide the alert in your own code. If the system reports a problem, the alert is displayed permanently and the user cannot close it.

The alert is dismissed with the close icon in the corner; do not duplicate this with a button below the message text

The alert can contain links and buttons; the icon and heading can be omitted. In a lengthy notification, the text can be split into paragraphs.

Failed to upload the file
When a hyperlink is at the end of a sentence, the period takes the link color, but is not underlined.
Failed to upload the file
When a hyperlink is at the end of a sentence, the period takes the link color, but is not underlined.
Failed to update the agent ekb-mail-server
Failed to update the agent ekb-mail-server
The module is configured in the policy Hypervisors
The module is configured in the policy Hypervisors
After recovery, check the agent groups' links to policies
After recovery, check the agent groups' links to policies
Short text in the alert
Short text in the alert

A paragraph should convey and develop only one idea. For example, if you mix the causes, the essence of the problem, and possible solutions to the situation you are describing in a single paragraph, the reader will quickly get tired and most likely will not understand what they just read.

Try to state the key idea in the first sentence of the paragraph, then expand on it in more detail and back it up with examples. That way the reader can skim the text diagonally and immediately see what each part is about. Sometimes the first sentences of a paragraph are set in bold — these are called run-in headings.

A paragraph should convey and develop only one idea. For example, if you mix the causes, the essence of the problem, and possible solutions to the situation you are describing in a single paragraph, the reader will quickly get tired and most likely will not understand what they just read.

Try to state the key idea in the first sentence of the paragraph, then expand on it in more detail and back it up with examples. That way the reader can skim the text diagonally and immediately see what each part is about. Sometimes the first sentences of a paragraph are set in bold — these are called run-in headings.

  • Static alerts. The host applies only CSS classes and no ARIA role, which is correct for an alert rendered with the page: forcing role="alert" would make a screen reader announce page-load content unexpectedly.
  • Dynamically shown alerts. When an alert appears in response to a user action (a validation error, a status change), add role="alert" for urgent messages, or aria-live="polite" with aria-atomic="true" for non-urgent status, so assistive technology announces it. Alternatively, announce the message with LiveAnnouncer from @angular/cdk/a11y.
  • Status by icon alone. The status is conveyed by the icon color, which is not perceivable by every user. Repeat the severity in the title or body text (or add visually hidden text, e.g. <span class="cdk-visually-hidden">Error:</span>), and mark a decorative status icon aria-hidden="true".
  • Close control. Put the close button on a native <button> with an accessible name (aria-label="Close") so it is reachable and operable by keyboard.
  • Focus on dismiss. Dismissing an alert while focus is on its close control drops focus to <body>. Move focus to a logical target after removal — prefer FocusMonitor.focusVia from @angular/cdk/a11y so the focus ring is preserved.
Suggestions for improvement
If you found a mistake or want to improve the article, create an issue on GitHub.