Dev view
Alert
An inline non-blocking message that surfaces important information to the user — system status, validation errors, success confirmation, contextual warnings — and announces itself to assistive tech via an `aria-live` region. Distinct from Modal (blocking, demands response), Toast (auto-dismissed, transient), and Tooltip (on-demand description). Alert sits in the document flow, persists until dismissed or the underlying state changes, and may carry optional inline actions.
When to use
Use
When the user must be informed of a system state, validation result, or contextual situation that does not require immediate response — form submission errors, save confirmations, network warnings, system maintenance notices. Alert sits in the document flow, persists until dismissed or the underlying state changes, and announces via aria-live.
Avoid
For decisions or destructive confirmations that block the user — that is `Modal[variant=alertdialog]`. For transient auto-dismissed feedback — that is `Toast`. For on-demand descriptive text — that is `Tooltip`. For permanent informational content (page descriptions, instructions) — that is body prose, not Alert.
Versus related
- modal
`Modal[variant=alertdialog]` is a blocking confirmation that demands user response (focus trap + inert siblings). `Alert` is non-blocking and inline; the user may continue working while the alert is visible. Do not confuse the terminology — "alert" the inline message vs "alert dialog" the blocking modal.
- toast
`Toast` auto-dismisses after a short visible duration (3–7 seconds canonical); `Alert` persists until the user dismisses or the underlying state changes. Toast is for transient confirmations ("Saved"); Alert is for situations the user may need to revisit or act on.
- tooltip
`Tooltip` is on-demand description revealed by hover or focus; `Alert` is system-pushed announcement. Tooltip is pulled by the user; Alert is pushed by the system.
- banner
`Banner` is a region-wide persistent informational surface (e.g. a maintenance notice at the top of every page); `Alert` is contextual and tied to a specific situation (a form error, a recent action confirmation). Banner often spans the viewport width; Alert sits within a region.
Code anatomy
| Slot | Code slot | Semantic |
|---|---|---|
container | container | alert-or-status |
icon | icon | presentational |
title | title | heading-or-strong |
body | body | prose |
actions | actions | button-group |
dismiss-button | dismiss | button |
Variants, properties, states
Variants
Structurally different versions of the component.
infosuccesswarningerror Properties
The same component, parameterised.
| Property | Type |
|---|---|
dismissible | boolean |
hasIcon | boolean |
hasTitle | boolean |
density | comfortable | compact |
States
Browser/user-driven (interactive) vs. app-driven (data).
| Kind | States |
|---|---|
interactive | hoverfocus-visible |
data | openbusydismissed |
State transitions
| From | To | Trigger |
|---|---|---|
open | busy | User activates an action (e.g. Retry). The action handler is in flight; the alert's actions show a busy indicator and become non-activatable. The body and severity remain announced. |
busy | open | The action settles (success or failure). On success the consumer typically updates the alert's variant or replaces the alert with a new one; on failure the alert stays in error state with the failure cause appended. |
open | dismissed | User clicks the dismiss button (when `dismissible: true`). The alert is removed from the document and from the live region; focus moves to the next document focusable unless the alert was the only focusable in its container, in which case focus restores to the trigger that surfaced the alert (rare). |
Cross-framework expression
| Framework | Structure mechanism | Variant mechanism |
|---|---|---|
| Web Components | A `<ui-alert>` host with named slots for `icon` / `title` / `body` / `actions`; `role` reflected from the `severity` attribute (error/warning → alert; info/success → status) | attributes (`severity="error"`, `dismissible`, `density="compact"`); `data-state="open|busy|dismissed"` for CSS |
| React | Single `<Alert>` component with `severity` prop driving role; compound subcomponents (`Alert.Icon`, `Alert.Title`, `Alert.Body`, `Alert.Actions`) or named props for content | props with class-variance-authority for severity / density; `dismissible` boolean drives close-button visibility plus `onDismiss` callback |
| Angular (signals) | `<ui-alert>` component with content projection (`<ng-content select="[ui-alert-title]">`, `<ng-content select="[ui-alert-actions]">`); host bindings drive `[attr.role]` | input<'info' | 'success' | 'warning' | 'error'>(); `[dismissible]`, `[hasIcon]` host bindings; `output('dismiss')` |
| Vue | Single `<Alert>` SFC with named slots for `icon`, `title`, `body`, `actions`; `:severity` prop drives the role | defineProps with literal-union types; emits `dismiss` |
Events
dismissactionInvoke
Performance thresholds
stackDepthvisible-alert-count≥3alertsThe canonical maximum visible alert count per region is 3. Above this threshold, visual hierarchy collapses and SR announcement floods at page load. Replace stacks of 4+ with a summary alert linking to the full list rendered as a non-live region.
Accessibility
| Slot | Accessibility hint | |
|---|---|---|
container | Apply `role="alert"` for assertive severities (error, warning) where the user must attend immediately, or `role="status"` for polite severities (info, success) where the user should be informed but not interrupted. Both roles imply an implicit `aria-live` region; do not stack `aria-live` attributes on top. | |
icon | Decorative — set `aria-hidden="true"` on the icon. Severity is communicated to SR via the `role` (alert vs status) and through the title or body text, never through the icon glyph alone (icon-only severity violates WCAG 1.4.1 Use of Color and 1.3.3 Sensory Characteristics). | |
title | Use a real heading element of an appropriate level when the alert is a top-of-region announcement (e.g. a form error summary). For inline contextual alerts, a `<strong>` or styled `<p>` is sufficient — no heading is required. | |
body | Plain prose. The first user-facing text the SR announces when the alert mounts (after the role is announced). Avoid embedding actions inline — separate actions into the actions slot for keyboard reachability. | |
actions | Buttons keep native semantics. Order primary first (visually inline-end on LTR; SR announces in DOM order). Action buttons receive focus via Tab in document order; the alert does not auto-focus its actions on mount (that would interrupt the user's current task). | |
dismiss-button | Provide an accessible name ("Dismiss alert" or "Dismiss <severity> message"). Activation removes the alert from the live region; SR users do not hear a secondary "alert dismissed" announcement (the silence confirms removal). |
Accessibility acceptance
Keyboard walk
| Keys | Expected |
|---|---|
Tab | Focus moves through the alert in document order: actions first (in DOM order), then the dismiss button. The alert container itself is not focusable; the body is plain prose with no tabindex. |
Enter or Space (focus on action button) | Activates the action; alert transitions to `busy` while the consumer's handler runs. Focus stays on the action button (or moves to the dismiss button per consumer choice) after settle. |
Enter or Space (focus on dismiss button) | Dismisses the alert. Focus moves to the next document focusable; if the alert was the only content in its region, focus restores to the trigger that surfaced the alert (rare for inline alerts, common for transient success-after-submit). |
Tab (after dismiss) | Continues from where focus landed after dismissal. The dismissed alert is removed from DOM; subsequent Tab traverses remaining document focusables. |
Screen-reader announcements
| Trigger | Expected |
|---|---|
| Alert mounts in a live region (assertive severity) | SR interrupts the current announcement and reads the alert's role ("alert") followed by the title (if present) and body. Verbose modes may include the severity word ("Error:" prefix); polite-only modes hear only the body. |
| Alert mounts in a live region (polite severity) | SR queues the announcement after the current one completes — reads the role ("status") followed by title and body. Polite severity does not interrupt. |
| Alert action invoked, transitions to busy | Action button announces busy state via `aria-busy="true"`; SR users hear "<action label>, busy". The alert body text is not re-announced. |
| Alert dismissed | SR users do not hear a secondary "alert dismissed" announcement; the silence (and removal of the live region content) confirms removal. Avoid synthesising a "dismissed" announcement — it adds noise without value. |
axe-core rules to assert
aria-allowed-rolearia-required-attrcolor-contrastrole-img-altlandmark-uniqueempty-heading
Common mistakes
#alert-no-aria-live
Alert with no live-region announcement
The alert renders visually but the role is missing or the element is not in a live region. SR users do not hear the alert; the message is silently delivered to sighted users only.
Apply `role="alert"` for assertive severities (error, warning) or `role="status"` for polite severities (info, success). Both roles imply an implicit live region — do not stack `aria-live` on top. Test with at least one SR before shipping.
#alert-color-only-severity
Severity differentiated by colour alone
The alert's severity is communicated only through background or border colour. Colour-vision deficient users cannot distinguish info from error; SR users get no severity cue because the role is the same.
Triple-layer severity: visual (background + border + severity icon), accessible role (alert vs status), explicit prose ("Error:" prefix or named severity in title). Each layer redundantly communicates severity.
#alert-stacked-without-summary
More than three alerts stacked without summary
A page accumulates alerts (form validation errors, system messages, user feedback). The stack grows beyond three — visual hierarchy collapses, SR announcement floods at page load, the user cannot prioritise.
Cap canonical alert stacks at three. Beyond, render a summary alert ("3 errors prevent submission") with a link to the full list rendered as a regular region (not live). Document the threshold in the performance block.
#alert-actions-inside-prose
Alert actions embedded inline in body text
Body prose contains "Click here to retry" or similar embedded interaction. The interactive element is either an anchor (wrong semantic for an action) or a styled span with a click handler (no semantic at all).
Move actions to the dedicated actions slot as Button elements. The body describes the situation; actions are separately reachable.
#alert-dismiss-loses-issue
Dismiss removes the issue, not just the alert
The user dismisses an important warning by accident; the underlying issue (unsaved changes, expired session, network failure) silently persists. The alert was the only signal, and now the signal is gone.
Distinguish dismiss-the-alert from resolve-the-issue. For warnings of persistent system state, re-render the alert when the user next encounters the affected feature. For transient confirmations, dismissal is final by design. Document the contract per severity: error and warning alerts should not auto-disappear; info and success may.
Figma↔Code mismatches
- 01 Figma
An alert drawn with severity communicated by background colour alone
CodeSeverity is reflected via `role` (alert vs status) plus the icon glyph plus the visible severity word in the body
ConsequenceDesigners may rely on Figma's coloured background as the severity differentiator and skip the icon and the explicit severity word. Implementations following the Figma file ship colour-only severity — fails WCAG 1.4.1 (Use of Color) for users with colour-vision deficiencies, and fails for SR users entirely (the role is not implicit in colour).
CorrectSeverity is communicated through THREE layers: visual treatment (background, border, icon glyph), accessible role (alert vs status), and explicit prose (the body or title text names the severity for SR users).
- 02 Figma
A dismissible alert drawn with no clear undo affordance
CodeAn alert with destructive dismissal (the underlying state is also lost)
ConsequenceDesigners draw an "×" close button without considering what dismissal means. Developers ship `onDismiss` that simply removes the alert from the DOM; the user dismisses an important warning by accident, the warning is lost, and the underlying problem persists silently.
CorrectDistinguish dismiss-the-alert from dismiss-the-issue. Dismissing the alert is a UI affordance; dismissing the issue requires user action (Retry, Undo). Document both in the actions slot. For warnings of system state, the alert should re-appear when the underlying state next requires attention.
- 03 Figma
Multiple alerts drawn stacked at the top of a region
CodeMultiple alerts stacked dynamically, all wired to live regions
ConsequenceDesigners draw a stack of alerts in mocks; developers ship with each alert in its own live region. SR users hear a torrent of announcements at page load (every alert fires simultaneously); pointer users see a wall of severity treatment competing for attention.
CorrectLimit canonical alert stacks to 1–3. Beyond that, replace with a "summary alert" (e.g. "3 errors prevent submission") that links to the full list rendered as a non-live region. Document the canonical maximum in the performance block.
- 04 Figma
Alert actions drawn as inline links inside the body prose
CodeAlert actions as separate button elements in the actions slot
ConsequenceDesigners compose body text with embedded links ("Click here to retry"); developers either ship the literal anchor (link semantics for an action — see Link mistakes) or invent buttons that look like links (visual confusion). Keyboard reachability and SR announcements suffer either way.
CorrectAlert actions live in the dedicated actions slot as Button elements (potentially with `variant: tertiary` for visual restraint). Body prose names what the actions do ("Save failed.") without itself being interactive.