Skip to content
WunderUI

Alert

Free

An inline banner that tells people about the state of the page or a task, in five colours and two sizes.

npx wunderui-cli add alert

Playground

Installation

bash
npx wunderui-cli add alert

Writes the source into your project with its dependencies and, on first use, the styles - see Installation.

Then import what you need:

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

Then use it:

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

export function SavedNotice() {
  return (
    <Alert variant="positive">
      <AlertTitle>Settings saved</AlertTitle>
      <AlertDescription>Your notification preferences have been updated.</AlertDescription>
    </Alert>
  )
}

Expected result: You should see a green banner with a check icon, a bold title and one line of text under it.

When to use

Use Alert for

  • A message that belongs to the page or to one section and stays until the cause is fixed or the reader closes it
  • The result of a form or a bulk action, shown where people are looking
  • A notice at the top of a page, such as an ending trial or a planned maintenance window

Use something else for

  • Toast for a short confirmation that appears after an action and disappears by itself
  • Alert Dialog for a decision people must make before they can go on
  • Empty State for a list or a page that has nothing in it yet

Content

An alert holds a title and a line of text. Add a button when people can do something about it, and a close button when it can be put away.

Icon

The icon follows the colour: a check circle, or a warning triangle for negative and warning. Replace it with your own, or take it away.

Inline

size="inline" drops the box: a 12 px line of text with a 14 px icon, both in the colour of the variant. It is a static hint, so it has no role alert and is read in order. Plain is neutral and warning is yellow; the default icon is a shield check, a triangle for warning. It replaces InlineNote.

Only people with the link can join this workspace.

Keyboard interactions

The alert itself is not focusable. Only the action and the close button are in the tab order.

TaborShiftTab
Moves focus to the action and to the close button.
EnterorSpace
Presses the focused button: runs the action, or calls .

Behavior and motion

What the alert announces, how it is coloured and what it leaves to you.

Announcement
The alert is an assertive live region: a screen reader reads it as soon as it is added, and does not read one that was there at load. For a non-urgent message, use the polite status role.
Colour
A coloured alert has a tint fill with text, icon and border in the tint text colour of the same hue; plain uses the card colour. Every pair is a fixed token, so it works in light and dark.
Size
Large stacks title, text and action in a column. Small keeps them in one row, which fits above a table or at the top of a page; the text truncates there, so long messages belong in large.
Closing
Pressing the close button calls your handler; the alert does not remove itself. Stop rendering it yourself, and move focus somewhere sensible if the alert held it.
Width
The alert is a block that fills its container. Set the width on the container, not on the alert.
Motion
The alert has no entrance or exit animation. The close button sits at 70 % opacity and fades to 100 % on hover and focus.
Reduced motion
With reduced motion on nothing changes: the only motion is an opacity fade, which stays.

Anatomy

The parts of an alert, numbered in the figure. Only the description is needed; the title, icon, action and close button are optional.

  • data-slot="alert"

    The banner, with role alert. It comes in five variants (plain, positive, primary, negative, warning) and two sizes (large, small), and picks its icon from the variant. With size inline it is a static line of text without a box and without the role.

  • data-slot="alert-icon"Optional

    The leading icon: a check circle, or a warning triangle for negative and warning. You can replace it or hide it.

  • data-slot="alert-title"Optional

    The bold first line. In the small size it stays on one line and truncates only when the banner is very narrow.

  • data-slot="alert-description"

    The message. In large it wraps under the title; in small it takes the rest of the line and ends in an ellipsis.

  • data-slot="alert-close"Optional

    A native button named Dismiss, drawn only when a close handler is set.

  • Optional

    Any Button after the description, usually plain and small. In large it sits under the text; in small it ends the row.

  • Optional

Best practices

  • Do

    Say what happened in the title and what to do next in the text, like Changes couldn't be saved and Check your connection and try again.

  • Do

    Pick the colour for the meaning: positive for done, negative for failed, warning for attention, primary for information and plain for a neutral note.

  • Do

    Place the alert next to what it is about: under the field that failed, or at the top of the section it describes.

  • Do

    Give an alert that is only information a close button, and keep one that blocks people on the page until the cause is fixed.

  • Don’t

    Don't use an alert for a confirmation that should vanish by itself. A Toast fits a short message after an action.

  • Don’t

    Don't stack more than two or three alerts. Merge them into one, or move the details into a list.

  • Don’t

    Don't rely on the colour alone. The title and the text must say what happened, because not everyone sees the colour.

  • Don’t

    Don't put long text or a form in an alert. Link to a page for the details.

API reference

Alert is a div and takes every prop of a div. AlertTitle and AlertDescription are p elements and add no props of their own.

The banner, with role alert. It comes in five variants (plain, positive, primary, negative, warning) and two sizes (large, small), and picks its icon from the variant. With size inline it is a static line of text without a box and without the role.

PropTypeDefaultDescription
variant"warning" | "plain" | "primary" | "positive" | "negative""plain"The colour and meaning: for a neutral note, for success, for information, for an error and for attention. by default.
size"small" | "inline" | "large""large" stacks the title, the text and an action in a column; keeps them in one row; drops the box for a 12 px line of text with a 14 px icon and no . by default.
iconReactNode—Replaces the leading icon. Without it the alert shows a check circle, or a warning triangle for and ; with a shield check, or the triangle for . hides it.
onClose() => void—Called when the close button is pressed. The close button is only drawn when this is set.

The bold first line. In the small size it stays on one line and truncates only when the banner is very narrow.

The message. In large it wraps under the title; in small it takes the rest of the line and ends in an ellipsis.

PropTypeDefaultDescription
children requiredReactNode—
iconReactNode—
tone"neutral" | "warning""neutral"

Notes for AI

Give your coding assistant the Markdown reference instead of screenshots.

MCPget_component("alert")
Installnpx wunderui-cli add alert

The full library index for assistants is at /llms.txt.