Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Alert examples · Error

Error with Title and Action Alert for React

A destructive alert with a title and Retry and Dismiss buttons.

Framework
UI library

Errors need a way out. This React alert puts a Retry and a Dismiss button in AlertAction, at the end of a destructive Alert with a single AlertTitle, so the reader can recover without hunting for a control. Use it for temporary failures, such as a network error, where trying again is likely to work.

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.

FAQ

What is in this alert besides the title?

Retry and Dismiss, inside one AlertAction. The alert is variant="destructive" with a single AlertTitle and no description.

Which Button variants does the demo use?

Retry uses the destructive Button variant, so it matches the alert's color, and Dismiss uses outline, so it reads as the lesser choice. Both are size="xs", the size that fits beside the title in AlertAction.

Where do the buttons sit?

AlertAction is absolutely positioned at the top right, and the alert adds right padding so the title keeps its room. Both buttons go in that one slot, with className="flex gap-2".

What size should error alert action buttons be?

Small: the demo uses size="xs", which keeps the buttons the height of the title line so the alert stays compact. Larger buttons push the alert taller and compete with the message.

What does Dismiss do in this demo?

Nothing yet. The buttons have no click handlers, and Alert has no built-in dismiss. Keep whether the alert is shown in your own state, and have Dismiss stop rendering it.

Why are both buttons in one AlertAction?

AlertAction is a single absolutely positioned slot. A second one would sit on top of the first. Retry comes first in the row, Dismiss after it.