shadcn.io is not affiliated with official shadcn/ui
Alert examples · Error
Error with Everything Alert for React
A destructive alert with an error icon, a title, a description, and Retry and Dismiss buttons.
This is the full error alert: a CircleXIcon from Lucide, a title, a description, and Retry and Dismiss buttons, all in a destructive Alert. The icon goes first, and the alert gives it its own column so the title and description line up beside it. Use it for failures that need to stand out, such as a declined payment or a sync that stopped, where the reader needs the reason and a way to recover.
Preview
Installation
FAQ
When should error alerts include icons?
When the alert has to stand out among other content, such as at the top of a page or in a dashboard. An icon helps readers sort alerts at a glance: a circled X for errors, a triangle for warnings, an i for information. Inline next to a field that's already marked invalid, it adds little.
What color is the icon?
The variant's: with variant="destructive" the icon takes the destructive color along with the text. You don't set its color or size; the alert sizes an unsized icon and colors it for every variant.
How does the icon line up with the title?
The alert places a direct svg child in a first column that spans the title and description rows, and aligns it with the title's first line. Put the icon first, before AlertTitle, and the layout does the rest.
Does the icon need aria-hidden?
Here, yes: the title already says Error, so the icon is decorative and the demo sets aria-hidden="true" on it. If the icon were the only sign of severity, give the title that word instead of exposing the icon.
Should error icons be left or right of content?
At the start of the reading direction, where the eye lands first: left in English, right in Arabic or Hebrew. The alert's icon column follows the page's direction, so you don't change anything for right-to-left. Controls such as the buttons go at the end.
Related
- Error with Title, Description and Action AlertA destructive alert with a title, a
- Error with Title AlertA destructive alert with only a title
- Warning with Everything AlertA warning alert with a warning icon, a
- Error with Title and Action AlertA destructive alert with a title and
- Error with Title and Description AlertA destructive alert with a title and a
- Info with Everything AlertAn info alert with an info icon, a title