Skip to content

shadcn.io is an independent project built on shadcn/ui

Free

Warning with Title Alert for React

A warning alert that shows only the word Warning. No icon, no description, and no button, for a risk that fits on one line.

Only the title Warning, on a warning-tinted alert. No icon, no description, and no button.

Use it when the title already says what to watch, such as Unsaved changes. A blocking confirm is an Alert Dialog. In React, Base UI does not dismiss this.

Preview

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.
Use email insteadNo credit card

Anatomy

Alert anatomy: root, icon, title, description, action

Usage

<Alert className="max-w-lg" variant="warning">
  <AlertTitle>Warning</AlertTitle>
</Alert>

FAQ

When should I use title-only warning alerts?

When the title says what to watch out for and what to do is obvious: Storage almost full, Unsaved changes. If the reader would ask what happens if they ignore it, add an AlertDescription.

When should I use warning instead of error alerts?

A warning is about something that may go wrong; an error is about something that already did. An expiring plan or a nearly full disk is a warning; a failed payment is an error and uses variant="destructive".

Where does the amber styling come from?

From variant="warning": a faint tint of the theme's --warning color on the background, a stronger border, and the same color on any icon. The title keeps the regular text color, since amber text is hard to read on a light background.

Where should warning alerts appear on the page?

Before the thing it warns about: above a form whose submission is risky, at the top of a usage page for a quota. A warning after the action is too late to help.

Should warning alerts be dismissible or persistent?

Persistent while the condition holds: a warning about a full disk should stay until there's space. The Alert never hides itself, so it stays until your code stops rendering it. Let readers dismiss only warnings they can safely ignore.

Are warning alerts accessible to screen readers?

Yes: Alert renders with role="alert", so the warning is announced as soon as it appears. The title states the problem in text, so the amber color isn't the only signal.

API Reference

Alert

Sets variant="warning". The rest is on the Alert page.