Alert
<wa-alert>
Alerts are used to display important messages inline.
Unlike <wa-callout>, alerts are stateful and can be shown/hidden, optionally dismissed, and auto-hidden after a duration. Use alerts when the message lifecycle matters. Use callouts for static, always-visible messaging.
<wa-alert open> <wa-icon slot="icon" name="circle-info" library="cdn"></wa-icon> This is a standard alert. You can customize its content and even the icon. </wa-alert>
Alerts are only visible when the open attribute is present.
Examples
Jump to heading
Variants
Jump to heading
Set the variant attribute to change the alert's variant.
You can tell by how pretty the alert is.
You can safely exit the app now.
Settings will take effect on next login.
Please login again to continue.
We're very sorry to see you go!
<wa-alert variant="brand" open> <wa-icon slot="icon" name="circle-info" library="cdn"></wa-icon> <strong>This is super informative</strong><br /> You can tell by how pretty the alert is. </wa-alert> <br /> <wa-alert variant="success" open> <wa-icon slot="icon" name="circle-check" library="cdn"></wa-icon> <strong>Your changes have been saved</strong><br /> You can safely exit the app now. </wa-alert> <br /> <wa-alert variant="neutral" open> <wa-icon slot="icon" name="gear" library="cdn"></wa-icon> <strong>Your settings have been updated</strong><br /> Settings will take effect on next login. </wa-alert> <br /> <wa-alert variant="warning" open> <wa-icon slot="icon" name="triangle-exclamation" library="cdn"></wa-icon> <strong>Your session has ended</strong><br /> Please login again to continue. </wa-alert> <br /> <wa-alert variant="danger" open> <wa-icon slot="icon" name="circle-exclamation" library="cdn"></wa-icon> <strong>Your account has been deleted</strong><br /> We're very sorry to see you go! </wa-alert>
Closable
Jump to heading
Add the closable attribute to show a close button that will hide the alert.
<wa-alert variant="brand" open closable class="alert-closable"> <wa-icon slot="icon" name="circle-info" library="cdn"></wa-icon> You can close this alert any time! </wa-alert> <script> const alert = document.querySelector('.alert-closable'); alert.addEventListener('wa-after-hide', () => { setTimeout(() => (alert.open = true), 2000); }); </script>
Without Icons
Jump to heading
Icons are optional. Simply omit the icon slot if you don't want them.
<wa-alert variant="brand" open> Nothing fancy here, just a simple alert. </wa-alert>
Duration
Jump to heading
Set the duration attribute to automatically hide an alert after a period of time. This is useful for alerts that don't require acknowledgement. The timer pauses while the alert is hovered.
<div class="alert-duration"> <wa-button variant="brand">Show Alert</wa-button> <wa-alert variant="brand" duration="3000" closable> <wa-icon slot="icon" name="circle-info" variant="regular" library="cdn"></wa-icon> This alert will automatically hide itself after three seconds, unless you interact with it. </wa-alert> </div> <script> const container = document.querySelector('.alert-duration'); const button = container.querySelector('wa-button'); const alert = container.querySelector('wa-alert'); button.addEventListener('click', () => alert.show()); </script> <style> .alert-duration wa-alert { margin-top: var(--wa-space-m); } </style>
Importing
Jump to heading
Autoloading components via projects is the recommended way to import components. If you prefer to do it manually, use one of the following code snippets.
Let your project code do the work! Sign up for free to use a project with your very own CDN — it's the fastest and easiest way to use Web Awesome.
To manually import this component from NPM, use the following code.
import '@awesome.me/webawesome/dist/components/alert/alert.js';
To manually import this component from React, use the following code.
import WaAlert from '@awesome.me/webawesome/dist/react/alert';
Slots
Jump to heading
Learn more about using slots.
| Name | Description |
|---|---|
| (default) | The alert's main content. |
close-icon
|
An optional close icon to use instead of the default. |
icon
|
An optional icon to show in the alert. Works best with <wa-icon>. |
Attributes & Properties
Jump to heading
Learn more about attributes and properties.
| Name | Description | Reflects | |
|---|---|---|---|
appearanceappearance |
The callout's visual appearance.
Type
'accent' | 'filled' | 'outlined' | 'plain' | 'filled-outlined' |
|
|
closableclosable |
Makes the alert closable and shows the close button.
Type
booleanDefault
false |
|
|
css |
One or more CSSResultGroup to include in the component's shadow root. Host styles are automatically prepended.
Type
CSSResultGroup | undefinedDefault
[ ...(Array.isArray(WaCallout.css) ? WaCallout.css : WaCallout.css ? [WaCallout.css] : []), styles, ] |
||
durationduration |
The amount of time, in milliseconds, to wait before closing the alert. Set to
Infinity to disable.Default
Infinity |
||
openopen |
Indicates whether or not the alert is open. You can toggle this attribute to show and hide the alert.
Type
booleanDefault
false |
|
|
sizesize |
The callout's size.
Type
'small' | 'medium' | 'large'Default
'medium' |
|
|
variantvariant |
The callout's theme variant. Defaults to
brand if not within another element with a variant.Type
'brand' | 'neutral' | 'success' | 'warning' | 'danger'Default
'brand' |
|
Methods
Jump to heading
Learn more about methods.
| Name | Description | Arguments |
|---|---|---|
hide() |
Hides the alert. | |
show() |
Shows the alert. |
Events
Jump to heading
Learn more about events.
| Name | Description |
|---|---|
wa-after-hide |
Emitted after the alert closes and all animations are complete. |
wa-after-show |
Emitted after the alert opens and all animations are complete. |
wa-hide |
Emitted when the alert closes. |
wa-show |
Emitted when the alert opens. |
CSS custom properties
Jump to heading
Learn more about CSS custom properties.
| Name | Description |
|---|---|
--hide-duration |
The hide duration to use when applying built-in animation classes.
Default
150ms
|
--show-duration |
The show duration to use when applying built-in animation classes.
Default
150ms
|
CSS parts
Jump to heading
Learn more about CSS parts.
| Name | Description | CSS selector |
|---|---|---|
close-button |
The alert's close button, a <wa-button>. |
::part(close-button)
|
close-button__base |
The close button's exported base part. |
::part(close-button__base)
|
icon |
The container that wraps the optional icon. |
::part(icon)
|
message |
The container that wraps the alert's main content. |
::part(message)
|
Dependencies
Jump to heading
This component automatically imports the following elements. Sub-dependencies, if any exist, will also be included in this list.