Web · Components
Alert
A message that needs attention within the page.
4 exports
Live example
Preview
Code
Events
- Events appear here when you interact with the preview.
Import
A message that needs attention within the page. Title, description, icon, action and close button are given with props.
Screen reader behavior: messages already visible when the page loads need no role. For messages that appear later and must be announced right away use role="alert", and role="status" for less urgent ones. For short notifications that come and go use toast.
Examples
AlertVariant
typeStyle of the alert box.
AlertClassNames
interfaceClasses that can be given to the inner parts of Alert.
| Name | Type | Description |
|---|---|---|
icon? | string | Icon box. |
title? | string | Title. |
description? | string | Description (children). |
action? | string | Action area. |
AlertProps
interfaceProps of the Alert component.
Extends: Omit<ComponentProps<"div">, "title">
| Name | Type | Default | Description |
|---|---|---|---|
tone? | Tone | "neutral" | Color and default icon. |
variant? | AlertVariant | CustomVariant<"alert"> | "outline" | Style: built-in or a custom style added with defineAppearance. Defaults to UIProvider appearance.defaults.alert.variant. |
effect? | EffectProp | Effect or effects (e.g. "beam", ["border", "glow"]). The accent color comes from tone. See BuiltinEffect. | |
title? | ReactNode | Bold title. | |
icon? | IconProp | Icon left of the title: a name or an element. When omitted an icon matching the color is drawn; hidden with false. | |
action? | ReactNode | Action shown on the right (below on mobile), e.g. a Button. | |
onClose? | () => void | When given, a close (×) button appears at the top right and is called on click. | |
classNames? | AlertClassNames | Classes added to the inner parts. |