# Alert [component-header:sl-alert] Alerts are used to display important messages either inline or as toast notifications. ```html preview This is a standard alert. You can customize its content and even the icon. ``` ## Examples ### Types Set the `type` attribute to change the alert's type. ```html preview This is super informative
You can tell by how pretty the alert is.

Your changes have been saved
You can safely exit the app now.

Your settings have been updated
Settings will take affect on next login.

Your session has ended
Please login again to continue.

Your account has been deleted
We're very sorry to see you go!
``` ### Closable Add the `closable` attribute to show a close button that will hide the alert. ```html preview You can close this alert any time! ``` ### Without Icons Icons are optional. Simply omit the `icon` slot if you don't want them. ```html preview Nothing fancy here, just a simple alert. ``` ### Duration Set the `duration` prop to automatically hide an alert after a period of time. This is useful for alerts that don't require acknowledgement. ```html preview
Show Alert This alert will automatically hide itself after three seconds, unless you interact with it.
``` ### Toast Notifications To display an alert as a toast notification, or "toast", create the alert and call its `toast()` method. This will move the alert out of its position in the DOM and into [the toast stack](#the-toast-stack) where it will be shown. Once dismissed, it will be removed from the DOM completely. To reuse a toast, store a reference to it and call `toast()` again later on. You should always use the `closable` prop so users can dismiss the notification. It's also common to set a reasonable `duration` when the notification doesn't require acknowledgement. ```html preview
Primary Success Info Warning Danger This is super informative
You can tell by how pretty the alert is.
Your changes have been saved
You can safely exit the app now.
Your settings have been updated
Settings will take affect on next login.
Your session has ended
Please login again to continue.
Your account has been deleted
We're very sorry to see you go!
``` ### Creating Toasts Imperatively For convenience, you can create a utility that emits toast notifications with a function call rather than composing them in your HTML. To do this, generate the alert with JavaScript, append it to the body, and call the `toast()` method as shown in the example below. ```html preview
Create Toast
``` ### The Toast Stack The toast stack is a fixed position singleton element created and managed internally by the alert component. It will be added and removed from the DOM as needed when toasts are shown. When more than one toast is visible, they will stack vertically in the toast stack. By default, the toast stack is positioned at the top-right of the viewport. You can change its position by targeting `.sl-toast-stack` in your stylesheet. To make toasts appear at the top-left of the viewport, for example, use the following styles. ```css .sl-toast-stack { left: 0; right: auto; } ``` ?> By design, it is not possible to show toasts in more than one stack simultaneously. Such behavior is confusing and makes for a poor user experience. [component-metadata:sl-alert]