Alert
newA callout with Button's variants and colours, five sizes, and actions under the text or beside it.
Open Props in the corner of the example to try variant, color and size.
variant and color are Button's: solid, soft, subtle, outline, ghost and link in primary, neutral, destructive, success, warning and info. Both default to solid and primary. A colour declared for a button works on an alert too: <Alert color="brand">.
size, xs to xl, scales the padding, gaps, radius, type and icon together; md is the default. The icon is an svg placed first, and it sits centred on the title's first line.
Installation
Usage
<script setup lang="ts">
import { Info } from '@lucide/vue'
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
</script>
<template>
<Alert variant="subtle" color="info">
<Info />
<AlertTitle>Heads up!</AlertTitle>
<AlertDescription>You can add components to your app with the CLI.</AlertDescription>
</Alert>
</template>
Examples
Actions
AlertActions goes under the description. With orientation="horizontal" it moves to the end, and the icon, the text and the actions are centred against each other, whichever is tallest.
Close
AlertClose puts a close button at the end of the title's line and hides the alert. Bind v-model:open to bring it back or to know it was dismissed. The button takes the alert's text colour and follows its size, and the text keeps clear of it.
As a link
as renders another element; as-child merges the alert onto the single element you pass. variant="link" underlines the text on hover.
API Reference
Alert
class is also accepted on every part and merged over its classes with tailwind-merge.
| Prop | Default | Type and description |
|---|---|---|
| variant | "solid" | NonNullable<"solid" | "soft" | "subtle" | "outline" | "ghost" | "link" | null | undefined>Appearance, independent of colour, with Button's names. |
| color | "primary" | AlertColor | (string & {})Colour role the variant is drawn in. |
| size | "md" | AlertSizePadding, gaps, radius, type and icon size, from |
| orientation | "vertical" | "vertical" | "horizontal"
|
| asChild | — | booleanRender the single child instead of a wrapper, merging the alert's attributes and classes onto it. |
| as | "div" | AsTag | ComponentThe element or component to render. |
| open | true | booleanWhether the alert shows, for |
| Event | Payload and description |
|---|---|
| update:open | [value: boolean]Fires with |
| Slot | Scope and description |
|---|---|
| default | {}An icon as a direct |
AlertActions
| Slot | Scope and description |
|---|---|
| default | {}Buttons, under the description or at the end depending on the alert's orientation. |
AlertDescription
| Slot | Scope and description |
|---|---|
| default | {}Supporting text under the title. |
AlertTitle
| Slot | Scope and description |
|---|---|
| default | {}The alert's heading. |
AlertClose
| Slot | Scope and description |
|---|---|
| default | {}The icon, an X by default. |
class is also accepted on every part and merged over its classes with tailwind-merge.
Props
- variant
"solid" NonNullable<"solid" | "soft" | "subtle" | "outline" | "ghost" | "link" | null | undefined>Appearance, independent of colour, with Button's names.linkunderlines the text on hover, for an alert rendered as a link.- color
"primary" AlertColor | (string & {})Colour role the variant is drawn in.neutraluses the page's own foreground. Any other name picks up a colour you declare on[data-slot][data-color="<name>"].- size
"md" AlertSizePadding, gaps, radius, type and icon size, fromxstoxl.- orientation
"vertical" "vertical" | "horizontal"verticalstacks the actions under the description;horizontalputs them at the end and centres the icon, text and actions against each other.- asChild
booleanRender the single child instead of a wrapper, merging the alert's attributes and classes onto it.- as
"div" AsTag | ComponentThe element or component to render.- open
true booleanWhether the alert shows, forv-model:open.AlertClosesets it tofalse.
Emits
- update:open
[value: boolean]Fires withfalsewhenAlertClosecloses the alert.
Slots
- default
{}An icon as a directsvgchild, thenAlertTitle,AlertDescription,AlertActionsandAlertClose.
Slots
- default
{}Buttons, under the description or at the end depending on the alert's orientation.
Slots
- default
{}Supporting text under the title.
Slots
- default
{}The alert's heading.
Slots
- default
{}The icon, an X by default.
Data attributes
| data-slot | Attributes | Description |
|---|---|---|
| alert | data-variant, data-color, data-size, data-orientation | The root. |
| alert-title | — | The heading. |
| alert-description | — | The supporting text. |
| alert-actions | — | The actions, under the description or at the end. |
| alert-close | — | The close button, at the end of the title's line. |
Accessibility
The root has role="alert", so a screen reader announces an alert that appears while the page is open. For a notice that can wait until the reader is idle, pass role="status". An alert rendered as a link needs role="link", or it stops being announced as a link.