Skip to main content

Alert

Contextual feedback messages for typical user actions.

Bootstrap’s alert docs describe the markup and CSS.

Example

Put your message inside the alert. Without a theme, the alert uses neutral colors.

HTML
<div bsAlert>
  <p>A simple alert—check it out!</p>
</div>

Themes

Set theme to any Bootstrap theme color. Use .alert-link for matching links.

<div class="vstack gap-3">
  @for (theme of themes; track theme) {
    <div bsAlert [theme]="theme">
      <p>A simple {{ theme }} alert with <a href="#" class="alert-link">an example link</a>.</p>
    </div>
  }
</div>

Dismissing

Add dismissible to show a close button. The alert fades out, gets the hidden attribute, and emits closed. To remove it from the DOM, wrap it in @if. Focus on the close button moves to the next control on the page, so keyboard users keep their place.

@if (visible()) {
  <div bsAlert theme="warning" dismissible (closed)="visible.set(false)">
    <p>Something’s wrong. Check the fields below and try again.</p>
  </div>
} @else {
  <button type="button" bsButton="subtle" theme="secondary" (click)="visible.set(true)">
    Show the alert again
  </button>
}

Additional content

Alerts can contain headings, paragraphs and dividers.

HTML
<div bsAlert theme="success">
  <div class="vstack">
    <h3 class="alert-heading h4 mb-2">Well done!</h3>
    <p>You successfully read this important alert message.</p>
    <hr class="my-3" />
    <p class="mb-0">Use margin utilities to keep things nice and tidy.</p>
  </div>
</div>

API

BsAlert

Selector: [bsAlert] · Exported as: bsAlert

Inputs

NameTypeDefaultDescription
themeBsTheme | nullnullTheme color of the alert.
dismissiblebooleanfalseShows a close button.
closeLabelstring'Close'Accessible label of the close button.
animationbooleantrueFades the alert out when it closes.

Outputs

NameTypeDescription
closingvoidEmits when the alert starts to close.
closedvoidEmits after the alert is closed and its transition has finished.

Methods

NameTypeDescription
close()Promise<void>Closes the alert.
isClosedSignal<boolean>True after the alert has closed.