shadcn.io is not affiliated with official shadcn/ui
Payment successful
Your payment of $29.99 has been processed. A receipt has been sent to your email address.
New feature available
We've added dark mode support. You can enable it in your account settings.
Installation
bunx --bun shadcn@latest add https://kit.dev/r/aria/alert.jsonnpx shadcn@latest add https://kit.dev/r/aria/alert.jsonpnpm dlx shadcn@latest add https://kit.dev/r/aria/alert.jsonyarn shadcn@latest add https://kit.dev/r/aria/alert.jsonThis component depends on Button. Install it first if you haven't already.
Install the following dependencies:
bun add tailwind-variantsnpm install tailwind-variantspnpm add tailwind-variantsyarn add tailwind-variantsAdd the following to your globals.css.
:root {
--destructive-foreground: var(--color-red-700);
--info: var(--color-blue-500);
--info-foreground: var(--color-blue-700);
--success: var(--color-emerald-500);
--success-foreground: var(--color-emerald-700);
--warning: var(--color-amber-500);
--warning-foreground: var(--color-amber-700);
}
.dark {
--destructive-foreground: var(--color-red-400);
--info: var(--color-blue-500);
--info-foreground: var(--color-blue-400);
--success: var(--color-emerald-500);
--success-foreground: var(--color-emerald-400);
--warning: var(--color-amber-500);
--warning-foreground: var(--color-amber-400);
}Copy and paste the following code into your project.
import type React from "react";
import { tv, type VariantProps } from "tailwind-variants";
import { cn } from "@/lib/utils";
export const alertVariants = tv({
base: "cn-alert group/alert relative w-full",
defaultVariants: {
variant: "default",
},
variants: {
variant: {
default: "cn-alert-variant-default",
destructive: "cn-alert-variant-destructive",
info: [
"bg-info/4",
"border-info/32",
"[&_svg]:text-info",
"[&_[data-slot=alert-action]_[data-variant=ghost]]:hover:bg-info/10",Update the import paths to match your project setup.
Usage
import { CheckCircle2Icon, InfoIcon } from "lucide-react";
import {
Alert,
AlertDescription,
AlertTitle,
} from "@/components/ui/alert";<div className="grid w-full max-w-md items-start gap-4">
<Alert>
<CheckCircle2Icon aria-hidden="true" />
<AlertTitle>Payment successful</AlertTitle>
<AlertDescription>
Your payment of $29.99 has been processed. A receipt has been sent to
your email address.
</AlertDescription>
</Alert>
<Alert>
<InfoIcon aria-hidden="true" />
<AlertTitle>New feature available</AlertTitle>
<AlertDescription>
We've added dark mode support. You can enable it in your account
settings.
</AlertDescription>
</Alert>
</div>Demos
Basic
A basic alert with an icon, title and description.
Destructive
Use variant="destructive" to create a destructive alert.
Action
Use AlertAction to add a button or other action element to the alert.
Colors
Customize alert colors with classes such as bg-amber-50 dark:bg-amber-950.
Rtl
Right-to-left alert. See the RTL configuration guide for document direction.
API Reference
Alert
PropType
AttributeType
data-variant?stringAlertTitle
PropType
AttributeType
AlertDescription
PropType
AttributeType
AlertAction
PropType
AttributeType