Skip to main content

Blazor Alerts

Provide contextual feedback messages for typical user actions with the handful of available and flexible Blazor Bootstrap alert messages.


ChildContentRenderFragmentSpecifies the content to be rendered inside the alert.
ColorAlertColorGets or sets the alert color.AlertColor.None
DismissableboolEnables the alert to be closed by placing the padding for close button.false


CloseAsyncCloses an alert by removing it from the DOM.

Callback Events

OnCloseFires immediately when the close instance method is called.
OnClosedFired when the alert has been closed and CSS transitions have completed.



Alerts are available for any length of text, as well as an optional close button. For proper styling, use one of the eight colors.

Blazor Bootstrap: Alert Component
<Alert Color="AlertColor.Primary"> A simple primary alert - check it out! </Alert>
<Alert Color="AlertColor.Secondary"> A simple secondary alert - check it out! </Alert>
<Alert Color="AlertColor.Success"> A simple success alert - check it out! </Alert>
<Alert Color="AlertColor.Danger"> A simple danger alert - check it out! </Alert>
<Alert Color="AlertColor.Warning"> A simple warning alert - check it out! </Alert>
<Alert Color="AlertColor.Info"> A simple info alert - check it out! </Alert>
<Alert Color="AlertColor.Light"> A simple light alert - check it out! </Alert>
<Alert Color="AlertColor.Dark"> A simple dark alert - check it out! </Alert>

See alerts demo here.

Additional Content

Alerts can also contain additional HTML elements like headings, paragraphs and dividers.

Blazor Bootstrap: Alert Component - Alerts with additional content
<Alert Color="AlertColor.Success">
<h4 class="alert-heading">Well done!</h4>
<p>Aww yeah, you successfully read this important alert message. This example text is going to run a bit longer so that you can see how spacing within an alert works with this kind of content.</p>
<p class="mb-0">Whenever you need to, be sure to use margin utilities to keep things nice and tidy.</p>

See alerts with additional content demo.


Similarly, you can use Bootstrap Icons to create alerts with icons.

Blazor Bootstrap: Alert Component - Alerts with an icon
<Alert Color="AlertColor.Primary"> <Icon Name="IconName.InfoCircleFill" class="me-2"></Icon>An example alert with an icon </Alert>
<Alert Color="AlertColor.Success"> <Icon Name="IconName.CheckCircleFill" class="me-2"></Icon>A simple success alert with an icon </Alert>
<Alert Color="AlertColor.Danger"> <Icon Name="IconName.ExclamationTriangleFill" class="me-2"></Icon>A simple danger alert with an icon </Alert>
<Alert Color="AlertColor.Warning"> <Icon Name="IconName.ExclamationTriangleFill" class="me-2"></Icon>A simple warning alert with an icon </Alert>

See alerts with an icon demo.


  1. Using the Dismissable="true", it's possible to dismiss any alert inline.

It's possible to dismiss any alert inline. Here's how:

Blazor Bootstrap: Alert Component - Dismissing
<Alert Color="AlertColor.Warning" Dismissable="true"> <strong>Holy guacamole!</strong> You should check in on some of those fields below. </Alert>
  1. Manually we can close an alert with button click.
Blazor Bootstrap: Alert Component - Dismissing manually
<Alert @ref="warningAlert" Color="AlertColor.Warning">
<strong>Holy guacamole!</strong> You should check in on some of those fields below. <Button Color="ButtonColor.Primary" @onclick="CloseAlert">Close</Button>
@code {
Alert warningAlert;

private async Task CloseAlert() => await warningAlert?.CloseAsync();

See dismissable alerts demo.


When an alert is dismissed, the element is completely removed from the page structure. If a keyboard user dismisses the alert using the close button, their focus will suddenly be lost and, depending on the browser, reset to the start of the page/document. For this reason, we recommend subscribing to the OnClosed callback event and programmatically sets focus to the most appropriate location on the page.