Skip to content

ComponentsFeedback

Alert

An inline callout for messages that belong to the page — status, warnings, errors and announcements. Four styles, seven colors, default or custom icons, trailing actions and an optional dismiss button.

Source
A new version is available
Refresh the page to get the latest features and fixes.

Installation

pnpm dlx shadcn@latest add @desyne/alert

The CLI installs dependencies and any other components this one uses.

Usage

tsx
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
tsx
<Alert color="warning" showIcon>
  <AlertTitle>Heads up</AlertTitle>
  <AlertDescription>Your trial ends in 3 days.</AlertDescription>
</Alert>

Alerts are live regions

The default role follows the color. danger and warning alerts render with role="alert" (assertive — announced immediately, interrupting the user); every other color renders with role="status" (polite — announced when the user is idle). For static notices that are on the page from the start, pass role="note" so they aren't announced at all.

When to use

  • Alert — a message tied to a page or section that stays until the situation changes: a failed deploy, a form error, a plan limit, a maintenance notice.
  • Toast — brief, non-blocking feedback after an action ("Saved", "Invite sent") that disappears on its own.
  • Dialog with role="alertdialog" — when the user must make a decision before continuing.
  • Badge — a compact status label on an item, not a message.

Anatomy

tsx
<Alert icon={<Icon />} action={<Button />} onDismiss={…}>
  {/* leading icon: `icon`, or the tone's default with `showIcon` */}
  <AlertTitle />         {/* short summary */}
  <AlertDescription />   {/* details, lists, links */}
  {/* trailing `action` slot, then the dismiss button */}
</Alert>
PartRendersNotes
Alert<div role="alert"> or <div role="status">Root flex row. alert for danger/warning, status otherwise. Sets the tone variables and data-slot="alert".
Icon<svg>From icon, or the tone's default when showIcon is set. Sized to 16px and tinted with the tone.
Content<div>Column that wraps children (title, description and anything else).
AlertTitle<div>Medium-weight summary line.
AlertDescription<div>Muted supporting text. Can hold paragraphs, lists and links.
Action<div>Rendered when action is set. Vertically centered on the trailing side.
Dismiss<button>React Aria Button with aria-label="Dismiss", rendered when onDismiss is set.

Examples

Variants

soft (default) tints the whole surface. outline is a plain card with a colored icon, accent adds a colored leading bar for dense layouts, and solid fills with the tone for banners that must not be missed.

Soft
The default. A tinted surface for most in-page messages.
Outline
A card surface where only the icon carries the color.
Accent
A colored bar on the leading edge, for dense or neutral layouts.
Solid
Full color, for banners and messages that must stand out.

Colors

Match the color to the message: info (default) for neutral information, success for completed actions, warning for something that needs attention soon, danger for errors and failures, and neutral for low-emphasis notes. primary and brand are also available for product announcements.

Scheduled maintenance
The dashboard will be read-only on Sunday, 02:00–04:00 UTC.
Payment received
Invoice INV-2041 for $1,280.00 has been paid.
Draft
This page isn't published yet. Only editors can see it.

Title and description

Both parts are optional. Use a title alone for one-line confirmations, a description alone for explanatory notes, and both when the summary needs context.

Your profile has been updated.
Invoices are generated on the 1st of each month and emailed to the billing contact.

Custom icon

showIcon adds the tone's default icon (info, check, triangle or circle; neutral has none). Pass icon to use any other icon; it gets the same size and tint.

Workflows are here
Automate reviews, deploys and notifications without leaving the app.
You're offline
Changes are saved locally and will sync when you reconnect.

Rich content

AlertDescription accepts any content. Lists work well for validation summaries, and a Link can point to more detail.

Actions

action renders buttons on the trailing side, vertically centered. Keep it to one or two small buttons, and make sure the action is reachable elsewhere if the alert can be dismissed.

Update ready
Version 2.4.0 has been downloaded.

Dismissible

onDismiss adds a close button. The alert doesn't hide itself — remove it from your state in the callback, and persist the choice if it shouldn't come back on reload.

Domain verified
acme.com is connected. SSL certificates are issued automatically.

Showing results of an action

Render the alert conditionally after an async action. A danger alert has role="alert", so screen readers announce it as soon as it appears, without moving focus. A success or info result gets role="status" and is announced politely instead.

shadcn compatibility

The shadcn variant names still work: default maps to outline + neutral, and destructive maps to outline + danger. An explicit color wins over the alias.

Heads up!
You can add components to your app using the CLI.

Recipes

Billing banner

A full-bleed solid alert at the top of the app shell, with an action and a dismiss button. rounded-none makes it sit flush with the frame.

Acme Inc.Billing

Server error in a form

Field errors belong next to their fields; errors that come back from the server go in an alert above the form. Clear it when the user resubmits.

New project

Try “acme-web” to see the error.

Plan limit

An accent warning with a Meter inside the content column and an upgrade action.

Accessibility

  • The root is a live region whose urgency follows color: danger and warning get role="alert" (assertive — announced immediately when inserted or changed); every other color gets role="status" (polite — announced when the user is idle). Legacy variant="destructive" resolves to danger, so it stays assertive.
  • An explicit role always wins. Use role="note" for static content that's on the page from the start and shouldn't be announced, or role="alert" to make a non-danger tone urgent.
  • Live regions announce content that changes after they're in the DOM. For an alert that appears in response to an action, render it conditionally (as above) rather than toggling its text inside an always-present element.
  • Alerts never move focus. If the user must act, put the action in the alert and consider a Dialog instead.
  • Icons are decorative. The title (or description) must carry the meaning on its own; don't rely on color alone.
  • The dismiss button is a React Aria Button labelled "Dismiss", with a keyboard-only focus ring.
  • Avoid auto-dismissing alerts; users of assistive tech may not have finished reading them.

Keyboard

KeyAction
TabMoves focus to the action buttons and the dismiss button
Space / EnterActivates the focused button

Styling

Data slots

SlotElement
data-slot="alert"Root
data-slot="alert-title"AlertTitle
data-slot="alert-description"AlertDescription (text becomes --tone-fg at 85% on solid)

Tone variables

The color prop sets --tone and --tone-fg on the root; every variant styles itself from those. Set them yourself for a one-off color:

tsx
<Alert
  variant="accent"
  icon={<SparklesIcon />}
  className="[--tone:var(--color-violet-600)] [--tone-fg:white]"
>
  <AlertTitle>New in 2.4</AlertTitle>
</Alert>
VariableUsed for
--toneIcon color, border and tint (soft), leading bar (accent), background (solid)
--tone-fgText and icon on solid

alertVariants

The tailwind-variants function behind the root. Use it to style your own element as an alert.

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

<section className={alertVariants({ variant: "accent", color: "success" })}>…</section>;

API Reference

Alert

Prop

Type

Also accepts every prop of <div>.

AlertTitle / AlertDescription

Accept every prop of <div>.

alertVariants

Prop

Type

  • Toast — temporary, non-blocking feedback.
  • Dialog — for messages that need a decision.
  • Badge — compact status labels.
  • Meter — show the level behind a quota warning.