When to use
- For contextual guidance or inline recommendations: When users need clarification or additional context about their current task or when suggesting next steps within the workflow.
- To communicate warnings or issues: When an action requires attention, but isn’t blocking progress or the user can resolve the issue in a separate context.
- When actions need to be taken: If the user should resolve an issue directly within the Alert.
When to use something else
- When the message is critical and must be acknowledged: Use a Dialog instead to capture user attention.
- For system-wide notifications or alerts: Use a Sonner, Banner, or the notification center.
- For immediate feedback such as success or failure of an operation when the user does not need to be given a lot of details: Use a Sonner and allow them to try again.
- When the errors prevent the user from continuing such as “page not found”, “no access” or server error: Use a full page Empty state.
- If the information is not tied to a specific user action or context: Use Tooltips or inline text for passive guidance.
- If a form field requires validation: Use inline validation messages provided with Combobox, Input, Select, or Textarea.
Dos and don’ts
- Do use action Buttons when the action is specific to the message and will resolve (dismiss) it.
- Do consider other methods for feedback before using an Alert, such as inline validation on forms. Avoid mixing multiple feedback states as this becomes confusing or frustrating to a user.
- Do use the correct status type depending on the alert. If none exists, use a neutral or info type.
- Do place Alerts near the content they relate to and set the width.
- Do use a strip style Alert if the content must span the full page.
- Don’t use action Buttons for unrelated activities or activities that don’t resolve the Alert.
Placement
- Always align the edge of the Alert relative to the surrounding content. Alerts should never be flush to a container’s divider.
- Use the card style Alert when content needs to wrap and applies to a small container.
- Use the strip style Alert when content is short and applies to a larger container.
Behavior
- Inline to the page: it does not block the full viewport like a Dialog or Alert dialog.
- Dismissal removes the alert from the layout (or hides it) per variant; optional actions should complete or dismiss the alert in one clear step.
- If the alert includes focusable controls, manage focus appropriately; otherwise it typically does not trap focus.
- Product rules decide whether dismissed state persists across navigation or sessions.
Often used with
Button for dismiss or fix-it actions; optional inline icon; sits above related content, not inside unrelated Card chrome unless scoped to that region.Accessibility
- ARIA roles: Use
role="alert"(assertive) for urgent visual notifications requiring immediate user attention, androle="status"(polite) for routine status changes. - Color redundancy: Never rely on color alone (e.g., green/red fills) to distinguish success from error states—always pair with explicit icons and text prefixes like “Error:” or “Success:”.
- Contrast: Maintain a minimum text-to-background contrast ratio of 4.5:1 for light and dark variant alerts.