Alert

new

A callout with Button's variants and colours, five sizes, and actions under the text or beside it.

Demo

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.

Orientation

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.

With a close button

as renders another element; as-child merges the alert onto the single element you pass. variant="link" underlines the text on hover.

API Reference

Data attributes

data-slotAttributesDescription
alertdata-variant, data-color, data-size, data-orientationThe 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.

Changelog

  1. registry 0.22.0

    95b68d3 — Breaking: the focus ring's colour hook is --focus-ring-color, no longer --color-ring. focus-ring and focus-ring-inset read var(--focus-ring-color, --theme(--color-ring)), so a .dark island (or any subtree that sets --ring) rings its controls in its own --ring; a class such as [--color-ring:currentColor] copied from the kit now has no effect and becomes [--focus-ring-color:currentColor]. tone-control, AlertClose, BannerClose and the ChoiceGroup cards set the new variable.

    727fdf9 — A plain mt-* class on AlertDescription now sets its gap under AlertTitle; the built-in 4px gap comes through a variable instead of a selector that outranked the class.

    cb25aeb — AlertClose and BannerClose render type="button", so in a form they are no longer its default button: Enter in a field submits the form instead of closing the notice.

  2. core 0.16.0

    95b68d3 — Breaking: the focus ring's colour hook is --focus-ring-color, no longer --color-ring. focus-ring and focus-ring-inset read var(--focus-ring-color, --theme(--color-ring)), so a .dark island (or any subtree that sets --ring) rings its controls in its own --ring; a class such as [--color-ring:currentColor] copied from the kit now has no effect and becomes [--focus-ring-color:currentColor]. tone-control, AlertClose, BannerClose and the ChoiceGroup cards set the new variable.

  3. registry 0.21.0

    6d5114c — AlertClose: a close button for Alert, like BannerClose. It sits at the end of the title's line (centred when horizontal), takes the alert's text colour and a size that follows the alert's, and the text keeps clear of it. Alert gains v-model:open; the item now depends on button and @lucide/vue.

    e5495ef — size works the same way everywhere. Every component exports its size type (AlertSize, BadgeSize, CardSize, CheckboxSize, RadioSize, SwitchSize, EmptySize, InputFloatingSize, ItemSize, ListboxSize, SeparatorSize, SliderSize, StepperSize, TabsSize, TextareaSize, TimelineSize) and the props take it without null; Button-based parts take ButtonSize, Input TextControlSize, SelectTrigger SelectSize and Tree TreeSize. ToggleGroup and ToolbarToggleGroup carry data-size on the group as well. Table's row heights moved into tableSize, so a class on DataTable's ui.table overrides --table-row-h at every size, not only at md.

  4. registry 0.19.0

    adf96cd — Parts no longer style themselves from their root's size through group-data-[size=…] variants, which beat any plain class of yours. size is the density of the root, and a class on a part wins:

    - Card, Empty, Alert and Stepper: CardTitle, CardDescription, EmptyTitle, EmptyDescription, AlertTitle, AlertDescription, StepperTitle and StepperDescription keep one text size at every root size (title-md/body-md, title-sm/body-md for Alert, title-sm/body-sm for Stepper). Empty's icon and gaps and Stepper's indicator number still follow the size, through --empty-icon, --empty-header-gap, --empty-content-gap and --stepper-text on the root. - Menu and DrawerMenu labels, Menubar triggers and the Calendar heading, weekday cells and week numbers keep scaling with the size, through --menu-label, --menubar-text, --calendar-heading and --calendar-label (each with a -leading twin) set by the root. - AlertDialog size="sm" centres its text through the content, so text-start on AlertDialogHeader wins; the footer keeps its two-column grid.

  5. registry 0.8.0

    a2a4d38 — Button and Alert: the outline variant no longer paints bg-background, so an outline button or alert on a tinted surface shows the surface through it, as Badge's outline already did.

  6. registry 0.6.0

    715f6fc — Components are coloured by tones. A colour is three inputs, --tone, --tone-foreground and --tone-text, set on [data-slot][data-color="<name>"]; core derives --tone-soft, --tone-soft-foreground, --tone-border and --tone-border-subtle from them and registers all seven as tone-* colours, so bg-tone, text-tone-text and the rest work as classes. The --c-* variables are gone: a rule that set --c, --c-fg, --c-soft, --c-soft-fg or --c-edge now sets --tone, --tone-foreground and --tone-text, and drops the rest. Button, Badge, Alert, Toggle, the choice controls and Toast read tones; Toast no longer exports toastAccents.

  7. core 0.5.0

    715f6fc — Components are coloured by tones. A colour is three inputs, --tone, --tone-foreground and --tone-text, set on [data-slot][data-color="<name>"]; core derives --tone-soft, --tone-soft-foreground, --tone-border and --tone-border-subtle from them and registers all seven as tone-* colours, so bg-tone, text-tone-text and the rest work as classes. The --c-* variables are gone: a rule that set --c, --c-fg, --c-soft, --c-soft-fg or --c-edge now sets --tone, --tone-foreground and --tone-text, and drops the rest. Button, Badge, Alert, Toggle, the choice controls and Toast read tones; Toast no longer exports toastAccents.

  8. registry 0.3.0

    311dead — Add Alert: Alert, AlertTitle, AlertDescription and AlertActions, with Button's variants and colours, five sizes and two orientations.