Alert

Alert

An inline status message with a next step. Renders as a vertical card or a one-line banner.

Playground

title
description
type
variant
icon
action
dismissible
<Alert>
  <Info />
  <AlertTitle>Your trial ends soon!</AlertTitle>
  <AlertDescription>Upgrade to keep enjoying features.</AlertDescription>
  <AlertHandlers>
    <Button variant="secondary" size="sm" className="w-full">
      Update now
    </Button>
  </AlertHandlers>
</Alert>

Preview

The default type renders a card. Compose it from an icon, AlertTitle, AlertDescription, action buttons in AlertHandlers, and an optional top-right control in AlertAction.

<Alert>
  <Info />
  <AlertTitle>Your trial ends soon!</AlertTitle>
  <AlertDescription>Upgrade to keep enjoying features.</AlertDescription>
  <AlertHandlers>
    <Button variant="secondary" size="sm" className="w-full">
      Update now
    </Button>
  </AlertHandlers>
  <AlertAction>
    <Button variant="ghost" size="icon-xs">
      <X />
    </Button>
  </AlertAction>
</Alert>

Installation

npx shadcn@latest add https://espresso-base-ui.vercel.app/r/alert.json

Usage

import {
  Alert,
  AlertAction,
  AlertDescription,
  AlertHandlers,
  AlertTitle,
} from "@/components/ui/alert"
<Alert variant="info">
  <Info />
  <AlertTitle>Heads up!</AlertTitle>
  <AlertDescription>You can compose the parts freely.</AlertDescription>
  <AlertHandlers>
    <Button variant="secondary" size="sm">Got it</Button>
  </AlertHandlers>
</Alert>

Variants

variant sets the tone: default, success, info, warning and destructive. It tints the leading icon – and in the card layout it also recolors the button inside AlertHandlers (background, hover and active states), so you pass a plain secondary Button and the alert themes it.

<Alert variant="success">
  <CheckCircle2 />
  <AlertTitle>Success alert</AlertTitle>
  <AlertDescription>This is a success vertical alert.</AlertDescription>
  <AlertHandlers>
    <Button variant="secondary" size="sm" className="w-full">
      View changes
    </Button>
  </AlertHandlers>
</Alert>

<Alert variant="warning">
  <TriangleAlert />
  <AlertTitle>Unsaved changes</AlertTitle>
  <AlertDescription>Save before navigating away.</AlertDescription>
  <AlertHandlers>
    <Button variant="secondary" size="sm" className="w-full">
      Save now
    </Button>
  </AlertHandlers>
</Alert>

API reference

Alert is a compound component – the root takes the layout and tone props and shares them via context, so AlertTitle and AlertDescription automatically adapt their typography to the active layout. All parts render a div and accept className plus standard div props.

Alert

PropTypeDefaultDescription
type"default" | "banner""default"Layout – vertical card with shadow (default), or a page-wide banner on a bg-input surface.
variant"default" | "success" | "destructive" | "warning" | "info""default"Tone – tints the leading icon and, in the card layout, recolors the AlertHandlers button.
ComponentDescription
AlertTitleHeading line. Context-sized: text-sm in the card, text-base in the banner. Links inside are underlined.
AlertDescriptionSupporting copy in muted text. Context-sized: text-xs in the card, text-base in the banner. Supports multiple paragraphs and underlined links.
AlertHandlersAction-buttons row (data-slot="alert-button"). Buttons stretch full-width in the card layout; in banners a secondary button gets a raised surface background.
AlertActionFloating top-right container (data-slot="alert-action") – typically the close button. In a banner without AlertHandlers it flows inline at the trailing edge.

Icon

Pass any icon as a direct child of Alert. A direct svg child is auto-sized to size-4 (unless it carries its own size class) and tinted by the active variant; the title and description shift into the second grid column to sit beside it. Omit the icon and the content spans the full width.

Accessibility & styling hooks

The root renders role="alert", so screen readers announce it as a live status message. Every part exposes a data-slot attribute (alert, alert-title, alert-description, alert-button, alert-action), and the root also reflects its props as data-type and data-variant – target these from CSS for app-level overrides.

The alertVariants cva helper is also exported for building custom alert surfaces with the same layout and tone classes:

import { alertVariants } from "@/components/ui/alert"

<div className={cn(alertVariants({ type: "banner", variant: "info" }))}>
  ...
</div>

Search documentation

Search the component docs