Alert

Feedback
AI

Alert banners for important messages, notifications, and feedback. Includes support for AI-generated insights with gradient styling.

Preview

Interactive alert examples

Variants

All available alert styles

AI Insights & Tips

Use the AI variant for contextual hints, smart suggestions, and inline help

Without Title

Simple alerts with description only

Dismissible Alerts

Alerts with close button

Props

Alert component API reference

PropTypeDefaultDescription
variant'default' | 'ai' | 'info' | 'success' | 'warning' | 'error''default'Visual style variant for the alert
iconReact.ComponentTypeCustom icon component to override the default variant icon
onClose() => voidCallback when the close button is clicked. If provided, shows a dismiss button.
aria-live'polite' | 'assertive' | 'off'Based on variantControls how screen readers announce the alert. Defaults to 'assertive' for error/warning, 'polite' for others.
classNamestringAdditional CSS classes for custom styling

Usage

Import and implementation example

import { Alert, AlertTitle, AlertDescription } from '@/components/ui/alert'

export default function Example() {
  return (
    <Alert variant="success">
      <AlertTitle>Success</AlertTitle>
      <AlertDescription>
        Your changes have been saved.
      </AlertDescription>
    </Alert>
  )
}

Features

Built-in functionality

  • 6 variants: AI, default, info, success, warning, and error styles
  • AI variant: Gradient background with Lightbulb icon for AI-generated content
  • Icon support: Default semantic icons per variant, or provide custom icons
  • Dismissible: Optional close button with onClose callback
  • Flexible content: Use with AlertTitle, AlertDescription, or both
  • Dark mode: Full dark mode support with proper color contrast
  • Screen reader support: Uses aria-live with intelligent defaults based on variant

Accessibility

ARIA support and keyboard navigation

ARIA Attributes

role="alert"aria-live (polite/assertive)aria-atomic="true"aria-label (on close button)

Keyboard Navigation

KeyAction
TabMove focus to the dismiss button
Enter / SpaceDismiss the alert (when focused on close button)

Notes

  • Error and warning variants use aria-live="assertive" by default for immediate announcement
  • Info and success variants use aria-live="polite" to avoid interrupting the user
  • The close button is labeled "Dismiss alert" for screen readers
  • Decorative icons are hidden from screen readers with aria-hidden="true"

Related Components