Alert
A callout for important messages with status variants
Loading...
Installation
pnpm dlx shadcn@latest add https://prototyper-ui.com/r/alert.jsonnpx shadcn@latest add https://prototyper-ui.com/r/alert.jsonyarn dlx shadcn@latest add https://prototyper-ui.com/r/alert.jsonbunx --bun shadcn@latest add https://prototyper-ui.com/r/alert.jsonThis will add the following files to your project:
components/ui/alert.tsx
Usage
import { Alert, AlertTitle, AlertDescription } from "@/components/ui/alert";
<Alert>
<AlertTitle>Heads up!</AlertTitle>
<AlertDescription>
You can add components to your app using the CLI.
</AlertDescription>
</Alert>;Anatomy
<Alert>
<Icon />
<div>
<AlertTitle />
<AlertDescription />
</div>
</Alert>| Sub-component | data-slot | Purpose | Required |
|---|---|---|---|
Alert | alert | Root container with role="alert" | Yes |
AlertTitle | alert-title | Heading for the alert | No |
AlertDescription | alert-description | Supporting message text | No |
Examples
Destructive
Loading...
Success
Loading...
Warning
Loading...
Styling
Data Slots
Use data-slot attributes to target specific parts of the alert:
| Slot name | Element |
|---|---|
alert | Root <div> wrapper |
alert-title | Title <h5> |
alert-description | Description <div> |
Customization Examples
/* Make all alerts have a thicker left border */
[data-slot="alert"] {
@apply border-l-4;
}{
/* Override styles via className */
}
<Alert className="border-l-4">
<AlertTitle>Note</AlertTitle>
<AlertDescription>With left accent border.</AlertDescription>
</Alert>;API Reference
Alert
The root container with variant styles and role="alert".
Prop
Type
Extends React.ComponentProps<"div">. All standard div props are forwarded via ...props.
AlertTitle
Heading for the alert message.
Prop
Type
Extends React.ComponentProps<"h5">. All standard h5 props are forwarded via ...props.
AlertDescription
Supporting text rendered below the title.
Prop
Type
Extends React.ComponentProps<"div">. All standard div props are forwarded via ...props.
alertVariants
A cva helper exported for use outside of the <Alert> component.
Accessibility
Keyboard Interactions
Alert is a non-interactive presentational element and does not have keyboard interactions.
ARIA Attributes
- Alert renders with
role="alert", which causes screen readers to announce the content when it appears. - For non-urgent notifications, consider using
role="status"instead.