Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Alert examples · Standard

Standard with Title and Action Alert for React

A neutral alert with a title and View Details and Dismiss buttons.

Framework
UI library

A standard alert with actions invites a next step without urgency. This React alert puts View Details and Dismiss buttons in AlertAction, at the end of a plain Alert with a single AlertTitle, in the default style with no color tint. Use it for general notices with an optional follow-up, such as a completed job the reader may want to inspect.

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 does this standard alert contain?

An AlertTitle of Success, plus View Details and Dismiss in AlertAction. There is no variant, so the alert uses the default card background and border.

Which button variants does the demo use?

View Details is the default Button and Dismiss is variant="outline". Both are size="xs", in one AlertAction with className="flex gap-2".

Where do the buttons sit?

AlertAction is absolutely positioned at the top right. The alert adds right padding so the title keeps its room. The two buttons stay in one row.

Do the buttons do anything in this file?

No. Neither button has a click handler or an href. Alert also has no built-in dismiss, so Dismiss hides the alert only if your state stops rendering it.

How wide is the alert?

className="max-w-lg" on Alert caps it. The title is one word, which leaves the padded area for the two xs buttons.

How is this alert announced?

Alert defaults to role="alert", so the title is announced when it appears. Pass role="status" for a notice that should wait until the reader is idle.