# Alert (`.z-alert`)

> Dismissible inline message with status variants, styled by CSS and dismissed by the shared close system.

- **Kind:** css
- **Category:** feedback

## CSS Variables

| Variable | Default | Scope | Affects | Description |
| --- | --- | --- | --- | --- |
| `--z-alert-bg` | `var(--z-muted)` | `.z-alert` | `background-color` | Background base color, mixed with transparency using `--z-alert-bg-o`. |
| `--z-alert-bg-o` | `4%` | `.z-alert` | `background-color` | Background opacity percentage used in the background color mix. |
| `--z-alert-border` | `var(--z-border)` | `.z-alert` | `border-color` | Border base color, mixed with transparency using `--z-alert-border-o`. |
| `--z-alert-border-o` | `var(--z-border-o)` | `.z-alert` | `border-color` | Border opacity percentage used in the border color mix. |
| `--z-alert-color` | `var(--z-muted-f)` | `.z-alert` | `color` | Text base color, mixed with transparency using `--z-alert-color-o`. |
| `--z-alert-color-o` | `100%` | `.z-alert` | `color` | Text opacity percentage used in the text color mix. |
| `--z-alert-radius` | `var(--z-global-radius)` | `.z-alert` | `border-radius` | Corner radius of the alert box. |

## Events

| Event | Cancelable | Detail | Description |
| --- | --- | --- | --- |
| `z-alert:before-hide` | ✓ | `{ target: HTMLElement; trigger: HTMLElement \| null }` | Fires on the alert before it is dismissed. Cancelable: `preventDefault()` keeps the alert in the page. Detail carries `target` (the alert) and `trigger` (the clicked close element, or `null`). |
| `z-alert:hide` | — | `{ target: HTMLElement; trigger: HTMLElement \| null }` | Fires on the alert after dismissal is confirmed, before it is removed. Detail carries `target` and `trigger`. |

## Data Hooks

| Attribute | Values | Applies to | Role | Description |
| --- | --- | --- | --- | --- |
| `data-close` | — | `external-trigger` | `trigger` | Dismisses through the shared close system. An empty value closes the nearest `.z-alert` or `[data-dismissible]` ancestor of the trigger; a selector or `#id` value closes that target. Object syntax accepts `target`, `animation` (`false` to remove instantly), and `duration` in milliseconds (default 150). |
| `data-dismissible` | — | `host` | `marker` | Marks an element as dismissible without the `.z-alert` class; the close system's ancestor search matches `.z-alert, [data-dismissible]`. |

## CSS Classes

| Class | Role | Applies to | Description |
| --- | --- | --- | --- |
| `.z-alert` | `root` | `.z-alert` | Root class of the alert box: a padded, bordered, rounded container with a tinted background. |
| `.z-alert-close` | `element` | `.z-alert` | Close affordance positioned in the top inline-end corner; put `data-close` on the button or link that uses it. |
| `.z-alert-danger` | `modifier` | `.z-alert` | Danger variant: re-tints background, border, and text with the danger color. |
| `.z-alert-info` | `modifier` | `.z-alert` | Info variant: re-tints background, border, and text with the info color. |
| `.z-alert-success` | `modifier` | `.z-alert` | Success variant: re-tints background, border, and text with the success color. |
| `.z-alert-warning` | `modifier` | `.z-alert` | Warning variant: re-tints background, border, and text with the warning color. |

## Accessibility

> While a timed dismissal runs the alert is set `inert`, removing it from the tab order and accessibility tree before it is removed from the DOM.

## Notes

- Alerts have no component class: dismissal is driven by the shared close singleton (`singletons/close.ts`) through the document-level toggle delegate installed by the essentials bundle.
- Dismissal plays the `z-closing` transition (default 150 ms) and removes the alert when it ends; `animation: false` or `duration: 0` in the `data-close` value removes it instantly.
- Unclassed links inside an alert are underlined and medium-weight so they stand out against the tinted background.

## Guides

- [Styling with cls and stl](https://next.0build.dev/docs/guides/styling.md)
- [Translating Components](https://next.0build.dev/docs/guides/i18n.md)
- [Icon Resolution](https://next.0build.dev/docs/guides/icons.md)
- [The data-source Convention](https://next.0build.dev/docs/guides/data-source.md)
- [Openers & Triggers](https://next.0build.dev/docs/guides/triggers.md)
- [Dialog Behavior](https://next.0build.dev/docs/guides/dialogs.md)
- [Utilities](https://next.0build.dev/docs/guides/utilities.md)
- [Runtime](https://next.0build.dev/docs/guides/runtime.md)

## Related

- [Toast](https://next.0build.dev/docs/components/toast.md)
