---
title: Alert
description: Display contextual feedback, status notices, and announcement banners.
package: moraine
version: 0.11.0
repository: https://github.com/subframe7536/moraine
---

# Alert

> Display contextual feedback, status notices, and announcement banners.

## Anatomy

```text
Alert [component; slot=root]
├── icon [slot]
├── content [slot]
│   ├── title [slot]
│   └── description [slot]
├── actions [slot]
└── close [slot]
```

## Usage

Use Alert for inline feedback that stays in the page flow. Choose [Toast](https://moraine.subf.dev/components/toast.md) for
transient notifications and [BaseDialog](https://moraine.subf.dev/components/base-dialog.md) for feedback that must block the page. Alert
sets `role="alert"` with `aria-live="assertive"` for the `warning` and `error` types, and
`role="status"` with `aria-live="polite"` for the rest.

```tsx
import { Alert } from 'moraine'

export function Example() {
  return <Alert type="info" title="System update available" />
}
```

### Type and variant

`type` selects the semantic status: `default`, `info`, `success`, `warning`, and `error`. The
`info`, `success`, `warning`, and `error` types render a matching status icon; `default` renders
none. `variant` selects the surface treatment: `subtle` (default), `soft`, `outline`, and `solid`.

### Description layout

Pass `description` for a supporting line below the title. With a description, the root uses larger
padding and the title turns bold. `children` render after the title and description.

```tsx
<Alert type="warning" title="Storage almost full" description="You have used 85% of your quota." />
```

### Dismissal

Set `closable` to render a dismiss button. Clicking it closes the alert, plays the exit animation,
and removes the alert from the DOM. Use `open` with `onOpenChange` to control visibility, or
`defaultOpen` to start closed. `onOpenChange` fires only for user dismissal, and `onExitComplete`
fires after the alert leaves the DOM. Override the button's accessible label (`Close alert`) with
`translations={{ close: '...' }}`.

```tsx
const [open, setOpen] = createSignal(true)

<Alert closable open={open()} onOpenChange={setOpen} title="Changes saved" />
```

## Examples

### Show status across every type

Render one alert per `type` to compare their colors and status icons.

```tsx
import { Alert } from 'moraine'

export function Basic() {
  return (
    <div class="flex flex-col gap-3 max-w-xl w-full">
      <Alert type="default" title="Default announcement" />
      <Alert type="info" title="Informational note for users" />
      <Alert type="success" title="Success! Operation completed successfully" />
      <Alert type="warning" title="Warning: Please check your configuration" />
      <Alert type="error" title="Error: An unexpected error occurred" />
    </div>
  )
}
```

### Add a supporting description

Pass `description` to explain the title with a second line.

```tsx
import { Alert } from 'moraine'

export function Description() {
  return (
    <div class="flex flex-col gap-3 max-w-xl w-full">
      <Alert
        type="info"
        title="Account verification"
        description="We have sent a verification code to your email. Please confirm it within 24 hours."
      />
      <Alert
        type="success"
        title="Payment received"
        description="Your subscription is now active. Your next billing date is November 21, 2026."
      />
      <Alert
        type="warning"
        title="Storage limit approaching"
        description="You have used 85% of your available storage capacity. Consider upgrading your plan."
      />
      <Alert
        type="error"
        title="Deployment failed"
        description="The build process encountered syntax errors in src/index.ts. Check pipeline logs for details."
      />
    </div>
  )
}
```

### Offer actions

Put buttons in `actions` so the reader can respond from the alert.

```tsx
import { Alert, Button } from 'moraine'

export function Actions() {
  return (
    <div class="flex flex-col gap-3 max-w-xl w-full">
      <Alert
        type="info"
        title="Software update available"
        description="Version 2.4.0 includes important performance improvements."
        actions={
          <Button size="sm" variant="outline">
            Upgrade
          </Button>
        }
        closable
      />
    </div>
  )
}
```

### Let the reader dismiss an alert

Set `closable` for a dismiss button. Drive visibility with `open` and `onOpenChange`.

```tsx
import { Alert, Button } from 'moraine'
import { createSignal } from 'solid-js'

export function CloseExample() {
  const [open, setOpen] = createSignal(true)

  return (
    <div class="flex flex-col gap-3 h-30 max-w-xl w-full">
      <div>
        <Button variant="outline" size="sm" disabled={open()} onClick={() => setOpen(true)}>
          {open() ? 'Click Icon to Close' : 'Reopen Alert'}
        </Button>
      </div>
      <Alert
        open={open()}
        onOpenChange={setOpen}
        closable
        type="info"
        title="Dismissible notice"
        description="You can close this alert by clicking the close button on the right."
      />
    </div>
  )
}
```

### Span a banner across the page

Set `fullWidth` to remove the side borders and corner radius for an edge-to-edge banner.

```tsx
import { Alert } from 'moraine'

export function FullWidthExample() {
  return (
    <div class="flex flex-col gap-3 w-full">
      <Alert
        fullWidth
        type="warning"
        title="Scheduled maintenance notice"
        description="The platform will undergo scheduled maintenance tonight between 02:00 and 04:00 UTC."
        closable
      />
    </div>
  )
}
```

### Replace or hide the icon

Pass `icon` with an icon name or element to override the status icon. Pass `icon={false}` to hide it.

```tsx
import { Alert } from 'moraine'

export function CustomIconExample() {
  return (
    <div class="flex flex-col gap-3 max-w-xl w-full">
      <Alert
        type="default"
        icon="icon-tip"
        title="Pro tip"
        description="You can press Ctrl + K to quickly open the command palette from anywhere."
      />
      <Alert
        type="info"
        icon={false}
        title="No icon alert"
        description="This alert has icon={false} to suppress the default status icon."
      />
    </div>
  )
}
```

## API Reference

### Attributes

| Attributes | Slot | Description |
| --- | --- | --- |
| `data-close` | `alert` | — |
| `data-closed` | `alert` | Present when disclosure or transition content is closed. |
| `data-expanded` | `alert` | Present when the panel, accordion, or menu is expanded. |
| `data-full-width` | `alert` | — |
| `data-has-description` | `alert` | — |
| `data-type` | `alert` | — |

### Props

Props for Alert.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| actions | JSX.Element \| undefined | — | Buttons or links rendered in a container at the end of the alert, before the close button. |
| closable | boolean \| undefined | false | Whether to show a dismiss button at the end of the alert. Clicking it sets the open state to<br>`false`, which plays the exit animation and then removes the alert from the DOM. |
| closeIcon | IconT.Name \| undefined | 'icon-close' | Icon name shown inside the dismiss button. Only used when `closable` is `true`. |
| defaultOpen | boolean \| undefined | true | Uncontrolled default open state. |
| description | JSX.Element \| undefined | — | Supporting text rendered under the title. Its presence switches the alert to the multi-line<br>layout (larger icon); `children` render after it. |
| fullWidth | boolean \| undefined | false | Whether to display as an edge-to-edge banner with flat borders. |
| icon | IconT.Name \| undefined | — | Leading icon displayed in the alert.<br>- `undefined` (default): automatically resolves to the semantic icon of the `type` (`info`,<br>  `success`, `warning`, `error`), or none for `default`.<br>- `false` or `null`: hides the icon.<br>- `IconT.Name`: displays the specified icon shortcut (e.g. `'icon-tip'`) or custom JSX element. |
| onExitComplete | (() => void) \| undefined | — | Called once after the alert closed, its CSS exit animation (if any) has finished, and the<br>element has been removed from the DOM. |
| onOpenChange | ((open: boolean) => void) \| undefined | — | Called with the next open state when the user dismisses the alert through the close button.<br>It is not called when `open` is changed from outside. |
| open | boolean \| undefined | — | Controlled open state. Leave `undefined` for uncontrolled usage. A closed alert is removed<br>from the DOM after its exit animation, so it renders nothing. |
| title | JSX.Element \| undefined | — | Primary title, rendered in bold above the description. Nothing is rendered when empty. |
| translations | Translations \| undefined | — | Overrides the built-in strings for this instance, merged over the provider locale. The only<br>key is `close`, the accessible label of the dismiss button (default `'Close alert'`). |
| type | 'default' \| 'info' \| 'success' \| 'warning' \| 'error' \| undefined | 'default' | Semantic intent of the alert. |
| variant | 'subtle' \| 'soft' \| 'outline' \| 'solid' \| undefined | 'subtle' | Visual surface variant. |
| as | T \| undefined | 'div' | Element or component to render as. |
| children | JSX.Element \| undefined | — | Free-form content rendered in the content area after the title and description. |
| class | SlotClassValue \| undefined | — | Class applied to the component root or trigger element. |
| classes | Classes \| undefined | — | Family slot class defaults for this instance. |
| style | SlotStyleValue \| undefined | — | Style applied to the component root or trigger element. |
| styles | Styles \| undefined | — | Family slot style defaults for this instance. |

**`translations` example**

```tsx
import { Alert } from 'moraine'

<Alert closable title="Saved" translations={{ close: 'Dismiss' }} />
```
