Skip to content
shadcn.io is not affiliated with official shadcn/ui

Shadcn Alert for React and Tailwind

Displays an alert for user attention.

Installation

bunx --bun shadcn@latest add https://kit.dev/r/alert.json

Anatomy

The icon is any direct svg child (typically a Lucide icon). AlertAction is optional.

Alert
├── Icon (optional)
├── AlertTitle
├── AlertDescription
└── AlertAction (optional)

Usage

import {
  Alert,
  AlertAction,
  AlertDescription,
  AlertTitle,
} from "@/components/ui/alert";
<Alert>
  <AlertTitle>Heads up!</AlertTitle>
  <AlertDescription>You can add icons to alerts.</AlertDescription>
  <AlertAction>
    <Button size="xs" variant="ghost">Dismiss</Button>
    <Button size="xs">Update</Button>
  </AlertAction>
</Alert>

Variants

Default

Info

Warning

Success

Destructive

Examples

With icon

With action

Custom color

API Reference

asChild merges props onto a single child element.

Place a Lucide (or other) icon as a direct child of Alert, before the title. The root uses CSS :has(> svg) to reserve a column for it.

Alert

Root. Renders a div with role="alert" by default.

PropTypeDefaultDescription
variant"default" | "info" | "warning" | "success" | "destructive""default"Color and icon treatment.
rolestring"alert"ARIA role. Use "status" for non-urgent, non-interruptive messages.
asChildbooleanfalseRender the child element instead of a div.
classNamestring-Class names on the root.
AttributeDescription
data-slotalert
data-variant"default", "info", "warning", "success", or "destructive"
role"alert" unless overridden

AlertTitle

Heading of the message. Renders a div. Sits in the second grid column when an icon is present.

PropTypeDefaultDescription
asChildbooleanfalseMerge onto a single child (for example h2).
classNamestring-Class names on the title.
AttributeDescription
data-slotalert-title

AlertDescription

Supporting text. Renders a div. Muted foreground; stacks extra content with flex-col gap-2.5.

PropTypeDefaultDescription
asChildbooleanfalseMerge onto a single child.
classNamestring-Class names on the description.
AttributeDescription
data-slotalert-description

AlertAction

Slot for buttons or other controls. On sm and up it sits on the trailing edge and spans the title/description rows. Below sm it wraps under the text.

PropTypeDefaultDescription
asChildbooleanfalseMerge onto a single child.
classNamestring-Class names on the action slot.
AttributeDescription
data-slotalert-action

Ghost buttons inside the action slot pick up a variant-tinted hover from the root (data-variant).

Accessibility

Follows the Alert WAI-ARIA pattern. The root defaults to role="alert" (assertive live region). For quiet confirmations, set role="status".

Do not put the only copy of severity in a decorative icon. If the title already says “Error” or “Success”, mark the icon aria-hidden="true". If the icon is the only severity cue, leave it exposed to assistive tech.

Keyboard support

Alert is not a composite widget. Focusable controls inside AlertAction participate in the normal tab order.

KeyDescription
TabMove to the next control in the action slot.
Shift + TabMove to the previous control.