How to build an accessible Alert in React

role="alert" makes assistive tech announce the message when it appears; the dismiss control is a real button so it is reachable and labeled, and color is paired with an icon/title so meaning is not conveyed by hue alone

When to use a Alert

When not to use it

Accessibility

Role alert, verified at WCAG 2.2-AA.

Common mistakes

Avoid: Auto-dismissing an Alert on a timer to mimic a notification

Prefer: <Toast> for ephemeral feedback

Alerts persist by design; auto-hiding important inline context risks the user missing it

Example

<Alert variant="info" title="Heads up">Your trial ends soon.</Alert>

See the full Alert reference →