Alert
elements man ui/templates/alertA callout that draws attention to a message, with an icon, a title and an action.
Exampleimport { Alert, AlertTitle, AlertDescription, AlertAction } from "@elements/ui/alert"; import { Icon } from "@elements/ui/icon"; import { Button } from "@elements/ui/button"; <Alert variant="success" title="Payment successful" description="Your receipt is on its way."> <Icon name="check-circle" /> </Alert> <Alert variant="danger"> <Icon name="alert-circle" /> <AlertTitle>Payment failed</AlertTitle> <AlertDescription>Your card was declined.</AlertDescription> <AlertAction><Button size="sm">Retry</Button></AlertAction> </Alert>
Plain text with an inline link goes straight in the slot and reads as one paragraph, with or without an icon, a title or an action beside it.
Example<Alert variant="accent" role="none"> <Icon name="info" /> Your subscription is still active. Cancel it from <a href="/account">your account</a>. </Alert> <Alert variant="warning" role="none"> <Icon name="alert-circle" /> <AlertTitle>Card expiring</AlertTitle> Update it from <a href="/billing">billing</a> before <strong>Dec 1</strong>. <AlertAction><Button size="sm">Update</Button></AlertAction> </Alert>
Loose text shares one column with the parts when the AlertAction comes last. An AlertAction placed earlier still takes the inline end, and the parts keep their places, but loose text beside it belongs in an AlertDescription.
Parts
| Part | What it is |
|---|---|
AlertTitle |
.alert-title: the strong first line. |
AlertDescription |
.alert-description: the body, paragraphs and lists spaced. |
AlertAction |
.alert-action: controls at the top inline end, in their own column. |
icon |
Any direct <svg> child, such as <Icon name="info" />. |
Attributes
Alert
| Attribute | Type | Default | Description |
|---|---|---|---|
variant |
"neutral" | "info" | "success" | "warning" | "danger" | "accent" |
"neutral" |
neutral is a plain notice; the rest are the callout intents. |
title |
string |
"" |
Renders an AlertTitle. |
description |
string |
"" |
Renders an AlertDescription. |
role |
"alert" | "status" | "none" |
"alert" |
alert is announced at once, status politely, none not at all. |
class |
string |
"" |
Extra classes; custom colors go here. |
attrs |
Record<string, string | number | boolean | undefined> |
{} |
Other attributes: id, aria-*, data-*. |
AlertTitle, AlertDescription, AlertAction
| Attribute | Type | Default | Description |
|---|---|---|---|
class |
string |
"" |
Extra classes. |
Slots
| Slot | Part | Content |
|---|---|---|
default |
Alert |
An <Icon>, the parts, anything. The icon sits at the inline start and an AlertAction at the inline end; the title, description, loose text and inline links flow as one column between them. |
default |
each part |
The part's content. |
Data attributes
| Attribute | Values | On |
|---|---|---|
data-variant |
the variant | root |
Accessibility
- role="alert" by default, announced at once. Use role="status" for a polite message and role="none" for a notice that is on the page from the start.
- An alert never moves focus. Controls inside it keep their own keyboard behavior.
- The icon is decorative; the title says what happened, so color is never the only signal.
See also
- Icon (opens in a new tab): An inline stroke icon from the set the templates draw their own controls with, sized in pixels and colored by the text around it.
- Button (opens in a new tab): A button or a link that looks like one, in six variants and four sizes.
- Badge (opens in a new tab): A small label for a status, a count or a category, built on the pill.
- Card (opens in a new tab): A surface with a header, body and footer, built on the base card styles.
- Kbd (opens in a new tab): A keyboard key or shortcut, as text.
- Separator (opens in a new tab): A horizontal or vertical rule between content, semantic or decorative.