Alert

A notice for a status that should be announced.

Overview

Alert is a container with role="alert". Place an svg first when the notice needs an icon. AlertTitle carries the headline; AlertDescription holds supporting copy.

Preview

Customize

Variant

Installation

Add the component with the CLI. It copies the files in and installs anything they depend on.

npx vinyaas add alert

Usage

import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; function InfoIcon() { return ( <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" aria-hidden="true"> <circle cx="12" cy="12" r="10" /> <path d="M12 16v-4" strokeLinecap="round" /> <path d="M12 8h.01" strokeLinecap="round" /> </svg> ); } export function Notice() { return ( <Alert> <InfoIcon /> <AlertTitle>Heads up!</AlertTitle> <AlertDescription> You can add components and dependencies to your app using the CLI. </AlertDescription> </Alert> ); }

Examples

Basic

An icon, title, and description for a successful update.

Destructive

Use variant="destructive" for failures. Keep the reason in the description.

In practice

A billing Card carries a destructive Alert when a charge fails. The alert stays text-only.

Billing

Visa ending in 4242 · Renews Apr 1

API

Other attributes for the underlying element are passed through.

NameTypeDefaultDescription
variant"default" | "destructive""default"default is a neutral notice on a card surface. destructive keeps that surface and uses danger text, icon, and border.
classNamestring—Merged onto the alert, title, or description with cn.

Accessibility

The root is an alert, so assistive technology can announce it. The title and description do not get extra roles. The icon is decorative. Destructive alerts keep the failure in the text and use danger color for the text, icon, and border.