# Alert

> An inline message about the current view: what happened and what to do next.

Category: Feedback · Atomic level: molecule
Page: https://ui.dtheo.dev/docs/components/alert

## Install

```bash
npx dtheo@latest add alert
# or, with the shadcn CLI
npx shadcn@latest add https://ui.dtheo.dev/r/alert.json
```

Dependencies: clsx, tailwind-merge, class-variance-authority, lucide-react. Registry dependencies: utils.

## Exports

`Alert`, `AlertContent`, `AlertTitle`, `AlertDescription`, `AlertActions`

## Use it for

- A failed load with Retry
- A warning that affects the whole page

## Reach for something else

- Confirmation after an action: use a toast
- Errors for one field: use FieldError next to it

## Accessibility

- Warnings and errors use role="alert"; info and success use role="status".

## Examples

### alert

```tsx
import { RotateCwIcon } from 'lucide-react';
import { Alert, AlertActions, AlertContent, AlertDescription, AlertTitle } from '@/components/ui/alert';
import { Button } from '@/components/ui/button';

export default function AlertExample() {
  return (
    <div className="flex w-full max-w-xl flex-col gap-3">
      <Alert variant="destructive">
        <AlertContent>
          <AlertTitle>Traces for R-0412 did not load</AlertTitle>
          <AlertDescription>
            Bench&nbsp;3 stopped responding during the download. The run itself was saved.
          </AlertDescription>
        </AlertContent>
        <AlertActions>
          <Button size="sm">
            <RotateCwIcon aria-hidden="true" />
            Retry
          </Button>
        </AlertActions>
      </Alert>
      <Alert variant="warning">
        <AlertContent>
          <AlertTitle>Winding temperature is near its limit</AlertTitle>
          <AlertDescription>
            The motor reached 84&nbsp;°C of 90&nbsp;°C. Let it cool to 40&nbsp;°C before the next high-gain
            step.
          </AlertDescription>
        </AlertContent>
      </Alert>
      <Alert variant="info">
        <AlertContent>
          <AlertTitle>Bench 3 now runs firmware 4.18.2</AlertTitle>
          <AlertDescription>
            Runs from before the update are compared against the old reference,{' '}
            <span className="whitespace-nowrap">R-0409</span>.
          </AlertDescription>
        </AlertContent>
        <AlertActions>
          <Button size="sm">Release notes</Button>
        </AlertActions>
      </Alert>
      <Alert variant="success">
        <AlertContent>
          <AlertTitle>Gains approved</AlertTitle>
          <AlertDescription>
            Kp&nbsp;3.60 and Kd&nbsp;0.09 passed all five acceptance checks on R-0413.
          </AlertDescription>
        </AlertContent>
      </Alert>
    </div>
  );
}
```

## Used in

- Data table pattern (template): https://ui.dtheo.dev/docs/patterns/data-table
- Forms pattern (template): https://ui.dtheo.dev/docs/patterns/forms
- States pattern (template): https://ui.dtheo.dev/docs/patterns/states
