---
title: "Alert"
description: "An inline notice with an icon and a coloured edge, in info, success, warning and danger kinds."
---

Use it for a message that belongs to a place on the page and stays until the situation changes: a channel in slowmode, a bot that has gone offline, a form that saved. For something that happened a moment ago and can fade, use a [Toast](/docs/components/toast).

Pick the variant for what the message means. `danger` is for something broken or about to be lost, and `warning` for something the reader should know before going on.

_Live example of Alert — see the page for the rendered demo._

## Installation

```bash
npx newtui@latest add alert
```

npm dependencies: class-variance-authority.

Files written — React: components/ui/alert.tsx. Vue: components/ui/alert/Alert.vue, components/ui/alert/AlertTitle.vue, components/ui/alert/AlertDescription.vue, components/ui/alert/AlertActions.vue, components/ui/alert/index.ts.

## Usage

React:

```tsx
import { Alert } from "@/components/ui/alert"
```

Vue:

```ts
import { Alert, AlertTitle, AlertDescription, AlertActions } from "@/components/ui/alert"
```

## Examples

### With actions

`AlertActions` holds one or two small buttons under the text. Put the action that resolves the notice first.

_Live example of Alert — see the page for the rendered demo._

### Dismissible

The alert keeps no open state: render it while it applies and stop rendering it when the reader dismisses it. Rendering it again is also what makes a screen reader announce it.

_Live example of Alert — see the page for the rendered demo._

## API reference

**`Alert`**

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `variant` | `"info" \| "success" \| "warning" \| "danger"` | `"info"` | What kind of notice it is. Sets the edge colour, the icon and the default role. |
| `role` | `string` | — | Overrides the role the variant picks: `alert` for `danger`, `status` for the others. |

`AlertTitle`, `AlertDescription` and `AlertActions` are the parts inside it. A title alone is a complete alert; the actions row holds one or two buttons.

## Accessibility

A `danger` alert is `role="alert"` and interrupts a screen reader the moment it appears; the others are `role="status"` and are read when the reader is idle. Only render an alert when it applies, because one that is on the page from the start is not announced at all. The kind is carried by the icon's shape and by the words as well as the colour, so write a title that says what happened.

## Tokens

Alert reads its colours, radii and motion from the `--newt-*` tokens. Override a token rather than editing the component.
