Alert
Material Design 3 alert components for displaying important messages and notifications
Alert
Alerts provide important messages to users in a visually prominent way. They communicate information about system status, user actions, or other contextual messages.
Basic Usage
Basic Alert
This is a basic alert message.
<div class="alert">
<p>This is a basic alert message.</p>
</div>Alert Types
Info (Default)
Info Alert
This is an informational message.
<div class="alert alert-info">
<p>This is an informational message.</p>
</div>Success
Success Alert
Your action was completed successfully!
<div class="alert alert-success">
<p>Your action was completed successfully!</p>
</div>Warning
Warning Alert
Please review this warning before proceeding.
<div class="alert alert-warning">
<p>Please review this warning before proceeding.</p>
</div>Error
Error Alert
An error occurred. Please try again.
<div class="alert alert-error">
<p>An error occurred. Please try again.</p>
</div>Style Variants
Tonal (Default)
Tonal alerts use a subtle background color:
Tonal Alerts
Tonal info alert
Tonal success alert
<div class="alert alert-tonal alert-info">
<p>Tonal info alert</p>
</div>
<div class="alert alert-tonal alert-success">
<p>Tonal success alert</p>
</div>Filled
Filled alerts have a solid background:
Filled Alerts
Filled info alert
Filled warning alert
<div class="alert alert-filled alert-info">
<p>Filled info alert</p>
</div>
<div class="alert alert-filled alert-warning">
<p>Filled warning alert</p>
</div>Outlined
Outlined alerts have a border:
Outlined Alerts
Outlined success alert
Outlined error alert
<div class="alert alert-outlined alert-success">
<p>Outlined success alert</p>
</div>
<div class="alert alert-outlined alert-error">
<p>Outlined error alert</p>
</div>Standard
Standard alerts are minimal with just an icon and text:
Standard Alert
Standard info alert
<div class="alert alert-standard alert-info">
<p>Standard info alert</p>
</div>Alert Structure
Complete Alert
A full-featured alert with all components:
Complete Alert Structure
Information
This alert contains important information that you should be aware of.
<div class="alert alert-info">
<div class="alert-icon">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
</div>
<div class="alert-content">
<h4 class="alert-title">Information</h4>
<p class="alert-description">
This alert contains important information that you should be aware of.
</p>
</div>
<div class="alert-actions">
<button class="btn btn-sm btn-text">Learn More</button>
</div>
<button class="alert-close" aria-label="Close">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
</div>With Icon
Alert with Icon
Your changes have been saved successfully.
<div class="alert alert-success">
<div class="alert-icon">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7" />
</svg>
</div>
<div class="alert-content">
<p>Your changes have been saved successfully.</p>
</div>
</div>With Title and Description
Alert with Title and Description
Storage Limit Reached
You've used 95% of your available storage. Consider upgrading your plan or deleting old files.
<div class="alert alert-warning">
<div class="alert-icon">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" />
</svg>
</div>
<div class="alert-content">
<h4 class="alert-title">Storage Limit Reached</h4>
<p class="alert-description">
You've used 95% of your available storage. Consider upgrading your plan or deleting old files.
</p>
</div>
</div>With Actions
Alert with Actions
Payment Failed
We couldn't process your payment. Please update your payment method.
<div class="alert alert-error">
<div class="alert-icon">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
</div>
<div class="alert-content">
<h4 class="alert-title">Payment Failed</h4>
<p class="alert-description">
We couldn't process your payment. Please update your payment method.
</p>
</div>
<div class="alert-actions">
<button class="btn btn-sm btn-text">Dismiss</button>
<button class="btn btn-sm btn-tonal">Update Payment</button>
</div>
</div>With Close Button
Alert with Close Button
You have 3 unread notifications.
<div class="alert alert-info">
<div class="alert-content">
<p>You have 3 unread notifications.</p>
</div>
<button class="alert-close" onclick="this.parentElement.remove()" aria-label="Close">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
</div>Density
Compact
Compact Alert
Compact alert with reduced padding.
<div class="alert alert-compact alert-info">
<div class="alert-content">
<p>Compact alert with reduced padding.</p>
</div>
</div>Comfortable
Comfortable Alert
Success!
Comfortable alert with increased padding.
<div class="alert alert-comfortable alert-success">
<div class="alert-content">
<h4 class="alert-title">Success!</h4>
<p class="alert-description">Comfortable alert with increased padding.</p>
</div>
</div>Icon Examples
Common Alert Icons
Common Alert Icons
<!-- Info -->
<div class="alert-icon">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
</div>
<!-- Success -->
<div class="alert-icon">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
</div>
<!-- Warning -->
<div class="alert-icon">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" />
</svg>
</div>
<!-- Error -->
<div class="alert-icon">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
</div>Use Cases
Form Validation
Form Validation Alert
<form class="space-y-4">
<div class="alert alert-error">
<div class="alert-icon">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
</div>
<div class="alert-content">
<h4 class="alert-title">Validation Errors</h4>
<ul class="list-disc list-inside">
<li>Email is required</li>
<li>Password must be at least 8 characters</li>
</ul>
</div>
</div>
<!-- Form fields -->
</form>System Status
System Status Alert
Scheduled Maintenance
Our service will be offline for maintenance on Sunday, Oct 30 from 2:00 AM to 4:00 AM EST.
<div class="alert alert-warning">
<div class="alert-icon">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" />
</svg>
</div>
<div class="alert-content">
<h4 class="alert-title">Scheduled Maintenance</h4>
<p class="alert-description">
Our service will be offline for maintenance on Sunday, Oct 30 from 2:00 AM to 4:00 AM EST.
</p>
</div>
</div>Action Confirmation
Action Confirmation Alert
Email sent successfully to john@example.com
<div class="alert alert-success">
<div class="alert-icon">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7" />
</svg>
</div>
<div class="alert-content">
<p>Email sent successfully to john@example.com</p>
</div>
<button class="alert-close" onclick="this.parentElement.remove()" aria-label="Close">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
</div>Feature Announcement
Feature Announcement Alert
New Feature: Dark Mode
Check out our new dark mode! Toggle it in your settings.
<div class="alert alert-filled alert-info">
<div class="alert-icon">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11.049 2.927c.3-.921 1.603-.921 1.902 0l1.519 4.674a1 1 0 00.95.69h4.915c.969 0 1.371 1.24.588 1.81l-3.976 2.888a1 1 0 00-.363 1.118l1.518 4.674c.3.922-.755 1.688-1.538 1.118l-3.976-2.888a1 1 0 00-1.176 0l-3.976 2.888c-.783.57-1.838-.197-1.538-1.118l1.518-4.674a1 1 0 00-.363-1.118l-3.976-2.888c-.784-.57-.38-1.81.588-1.81h4.914a1 1 0 00.951-.69l1.519-4.674z" />
</svg>
</div>
<div class="alert-content">
<h4 class="alert-title">New Feature: Dark Mode</h4>
<p class="alert-description">
Check out our new dark mode! Toggle it in your settings.
</p>
</div>
<div class="alert-actions">
<button class="btn btn-sm btn-text">Try It Now</button>
</div>
</div>Best Practices
Use Appropriate Types
Match alert types to the message intent:
- Info: General information, tips, announcements
- Success: Confirmations, completions, positive outcomes
- Warning: Cautions, potential issues, important notices
- Error: Failures, errors, critical problems
Be Concise
Keep alert messages brief and actionable:
Good Alert Example
Upload Failed
File size exceeds 10MB limit.
We encountered an issue while attempting to upload your file to our servers. The file you selected appears to be larger than the maximum allowed file size...
<!-- Good: Clear and concise -->
<div class="alert alert-error">
<div class="alert-content">
<h4 class="alert-title">Upload Failed</h4>
<p class="alert-description">File size exceeds 10MB limit.</p>
</div>
</div>
<!-- Avoid: Too verbose -->
<div class="alert alert-error">
<div class="alert-content">
<p>We encountered an issue while attempting to upload your file to our servers. The file you selected appears to be larger than the maximum allowed file size...</p>
</div>
</div>Provide Actions
When possible, offer next steps:
Alert with Next Steps
Session Expiring Soon
Your session will expire in 5 minutes.
<div class="alert alert-warning">
<div class="alert-content">
<h4 class="alert-title">Session Expiring Soon</h4>
<p class="alert-description">Your session will expire in 5 minutes.</p>
</div>
<div class="alert-actions">
<button class="btn btn-sm btn-tonal">Stay Logged In</button>
</div>
</div>Accessibility
- Use proper ARIA roles and labels
- Ensure sufficient color contrast
- Provide descriptive close button labels
- Use semantic HTML
Accessible Alert
An error occurred
<div role="alert" class="alert alert-error">
<div class="alert-content">
<p>An error occurred</p>
</div>
<button class="alert-close" aria-label="Dismiss error message">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
</div>Framework Examples
React with Dismiss
import { useState } from 'react';
interface AlertProps {
type?: 'info' | 'success' | 'warning' | 'error';
variant?: 'tonal' | 'filled' | 'outlined' | 'standard';
title?: string;
children: React.ReactNode;
dismissible?: boolean;
}
export function Alert({ type = 'info', variant = 'tonal', title, children, dismissible = false }: AlertProps) {
const [isVisible, setIsVisible] = useState(true);
if (!isVisible) return null;
return (
<div className={`alert alert-${variant} alert-${type}`} role="alert">
<div className="alert-content">
{title && <h4 className="alert-title">{title}</h4>}
<div className="alert-description">{children}</div>
</div>
{dismissible && (
<button
className="alert-close"
onClick={() => setIsVisible(false)}
aria-label="Close alert"
>
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
)}
</div>
);
}
// Usage
<Alert type="success" title="Success" dismissible>
Your changes have been saved.
</Alert>
API Reference
Class Names
| Class | Description |
|---|---|
.alert | Base alert styles (required) |
.alert-info | Info type (blue) |
.alert-success | Success type (green) |
.alert-warning | Warning type (yellow) |
.alert-error | Error type (red) |
.alert-tonal | Tonal variant (default) |
.alert-filled | Filled variant |
.alert-outlined | Outlined variant |
.alert-standard | Standard variant |
.alert-compact | Reduced padding |
.alert-comfortable | Increased padding |
.alert-icon | Icon container |
.alert-content | Content container |
.alert-title | Alert title |
.alert-description | Alert description |
.alert-actions | Action buttons container |
.alert-close | Close button |