shadcn-html / alert
Built with: CSS
Alert
A callout for important messages. Supports default and destructive variants with optional icons and actions.
Default
Informational alert with icon, title, and description.
Account updated successfully
Your profile information has been saved. Changes will be reflected immediately.
<div class="alert" role="alert">
<svg class="alert-icon" aria-hidden="true">...</svg>
<div class="alert-content">
<h5 class="alert-title">Account updated</h5>
<p class="alert-description">Your profile has been saved.</p>
</div>
</div>
Destructive
Error or warning variant.
Payment failed
Your payment could not be processed. Please check your payment method and try again.
<div class="alert" data-variant="destructive" role="alert">
<svg class="alert-icon" aria-hidden="true">...</svg>
<div class="alert-content">
<h5 class="alert-title">Payment failed</h5>
<p class="alert-description">Please try again.</p>
</div>
</div>
With Action
Alert with an action button.
Dark mode is now available
Enable it under your profile settings to get started.
<div class="alert" role="alert">
<svg class="alert-icon" aria-hidden="true">...</svg>
<div class="alert-content">
<h5 class="alert-title">New feature</h5>
<p class="alert-description">Enable it in settings.</p>
</div>
<div class="alert-action">
<button class="btn" data-variant="outline" data-size="sm">Enable</button>
</div>
</div>
CSS view file
Styles for the alert component. Uses design tokens for colors, spacing, and radius.
@layer components {
.alert {
position: relative;
display: flex;
align-items: flex-start;
gap: 0.75rem;
border: 1px solid var(--border);
border-radius: var(--radius-lg);
padding: 1rem 1.25rem;
font-size: 0.875rem;
color: var(--foreground);
background-color: var(--background);
&[data-variant="destructive"] {
border-color: var(--destructive);
color: var(--destructive);
& .alert-title {
color: var(--destructive);
}
& .alert-description {
color: var(--destructive);
opacity: 0.9;
}
& .alert-icon {
color: var(--destructive);
}
}
}
.alert-icon {
width: 1rem;
height: 1rem;
flex-shrink: 0;
margin-top: 0.125rem;
color: var(--foreground);
}
.alert-content {
flex: 1;
min-width: 0;
}
.alert-title {
margin: 0;
font-size: 0.875rem;
font-weight: 500;
line-height: 1.4;
letter-spacing: -0.01em;
color: var(--foreground);
}
.alert-description {
margin: 0.25rem 0 0;
font-size: 0.8125rem;
line-height: 1.5;
color: var(--muted-foreground);
}
.alert-action {
flex-shrink: 0;
margin-left: auto;
align-self: center;
}
}