Summit
ComponentsFeedback

Alert

An Alert shows users a short message in the page about a status, such as a payment that failed.

When to Use

  • for a status that lasts as long as its cause, for example “INV-2026-012 is overdue”
  • when one click can fix the cause, with an action like “Retry” next to “The payment failed”

When Not to Use

  • for the result of an action, like “Invoice sent” (use a toast from Sonner)
  • for a decision that users have to make before anything else (use an Alert Dialog)
  • for an error in one field of a form (use the FieldError of a Field)
  • for the status of one record in a list (use a Badge)
AlertToastAlert Dialog
PurposeA status that lastsThe result of an actionA decision before an action
PositionIn the page, where it is writtenA corner of the screen, the bottom right by defaultThe center of the screen
DurationUntil the page removes it4 seconds, or until it is closedUntil it is answered
Page BehindInteractiveInteractiveBlocked
FocusStays where it isStays where it isMoves into the popup
RolealertA list item in a live region set to politealertdialog

Anatomy

ElementUsage
IconOptional
Title*Optional
ActionOptional
ContainerRequired
Description*Optional

* An Alert has a title, a description, or both.

The icon is any svg that is a direct child of Alert.

Variants

VariantPurpose
defaultA notice that is neither good nor bad, such as a trial that ends soon
successA good outcome, such as a payment received
warningA state that needs attention, such as an overdue invoice
destructiveAn error or a loss, such as a failed payment

The variant changes only the color of the icon. Alert doesn’t render an icon, so you pass one. The preview uses InfoIcon, CheckCircleIcon, WarningIcon, and XCircleIcon, which are the icons that a toast shows for the same statuses.

Add an icon and a title that states the status in words to every Alert, as the variants look the same when there is no icon.

DoUse the variant with its icon and a title that states the status.
Don’tWhen the icon is left out, the Alert looks like a default one, and users who scan the page will miss the failure.

Behavior

An Alert is as wide as its container. It has no close button and isn’t dismissed automatically, so render it for as long as its condition is true.

Content

StringRuleExampleCounterexample
TitleSay what happened or what is due, with no period at the end“The payment failed”“Error”
DescriptionGive the cause and the next step“The card was declined. Ask the client for another payment method.”“Something went wrong.”
ActionOne verb“Retry”“Click here”

Accessibility

Alert renders a div with role="alert", which is a live region that is assertive and atomic. AlertTitle is a div, not a heading. An Alert can’t receive focus and has no keys; users reach the Button in its action with Tab.

Most screen readers announce an Alert immediately when it is added after the page has loaded. If an Alert is already in the page when it loads, it isn’t announced, according to the ARIA Authoring Practices Guide. If the message can wait its turn, pass role="status", which is polite.

Set aria-hidden on the icon. See Iconography for the rule.

The title must state the status in words so that users who can’t tell colors apart can read it, as WCAG 2.2 SC 1.4.1 Use of Color requires. The variant changes only the color of the icon.

Installation

npx shadcn@latest add @summit/alert

Usage

import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert';
import { InfoIcon } from '@phosphor-icons/react';

<Alert>
    <InfoIcon aria-hidden />
    <AlertTitle>Your trial ends in 5 days</AlertTitle>
    <AlertDescription>Add a payment method to keep sending invoices.</AlertDescription>
</Alert>;

Show a Status

To show a status, set variant and pass the icon for that status.

Show a Status
import { WarningIcon } from '@phosphor-icons/react';

<Alert variant="warning">
    <WarningIcon aria-hidden />
    <AlertTitle>INV-2026-012 is overdue</AlertTitle>
    <AlertDescription>It was due 12 days ago.</AlertDescription>
</Alert>;

Add an Action

To add an action, write AlertAction last and place an xs Button in it.

Add an Action
import { Alert, AlertAction, AlertDescription, AlertTitle } from '@/components/ui/alert';
import { Button } from '@/components/ui/button';
import { XCircleIcon } from '@phosphor-icons/react';

<Alert variant="destructive">
    <XCircleIcon aria-hidden />
    <AlertTitle>The payment failed</AlertTitle>
    <AlertDescription>The card was declined. Ask the client for another payment method.</AlertDescription>
    <AlertAction>
        <Button variant="outline" size="xs">
            Retry
        </Button>
    </AlertAction>
</Alert>;

Change the Role

By default, the role is alert. If the message can wait its turn, pass another role.

Change the Role
import { CheckCircleIcon } from '@phosphor-icons/react';

<Alert role="status" variant="success">
    <CheckCircleIcon aria-hidden />
    <AlertTitle>Payment received</AlertTitle>
</Alert>;

API Reference

The parts accept the props of a div.

Alert

PropTypeDefaultDescription
variant'default' | 'destructive' | 'success' | 'warning''default'The color of the icon

On this page