Alert
An inline notification banner for surfacing status, warnings, or errors. Alerts support six semantic intents, optional titles, actions, and dismissal.
Live Sandbox
This is a hydrated playground for the component. Toggle "Live preview" on the block below to swap the static HTML render for a real Livewire instance — every prop in the component's sandbox schema becomes an editable form field inside the iframe, so you can try different prop combinations live without writing any local code.
Basic Usage
Variants
Each intent has a distinct semantic meaning and color: primary for news about the product, neutral for a notice that carries no severity, and the four severities. The background is a subtle tint derived via color-mix() from the matching token.
With Title
Give the title a level, 1 to 6, to make it a heading of that level in the alert's own size, so a reader moving
from heading to heading finds it. Without level it is drawn as a heading and read as text.
<x-wirekit::alert intent="warning" title="Unsaved changes" :level="2">
You have unsaved changes that will be lost if you leave this page.
</x-wirekit::alert>
Dismissible
Add dismissible to render a close button. Dismissal is handled by an Alpine x-data block, so it needs nothing beyond the Alpine already on the page.
Actions Slot
Attach action buttons below the message via the actions slot:
Without Icon
Hide the default intent icon with :icon="false". This yields a quieter look — useful inside compact layouts or when the surrounding copy already conveys the severity.
Width & Layout
Alerts are block-level elements that fill their parent container by default. Control the width with Tailwind utility classes directly on the component — class is applied to the root element:
{{-- Constrain to a max width --}}
<x-wirekit::alert class="max-w-lg" intent="info">Narrow alert.</x-wirekit::alert>
{{-- Fixed width --}}
<x-wirekit::alert class="w-96" intent="success">Fixed 384px wide.</x-wirekit::alert>
{{-- Center a constrained alert --}}
<x-wirekit::alert class="max-w-md mx-auto" intent="warning">Centered alert.</x-wirekit::alert>
Height is determined automatically by the content. The alert grows to fit its message, title, and actions.
After an Action
The message after an action is usually an alert the next render brings:
{{-- 1. Shown once the action has run --}}
@if ($notice !== null)
<x-wirekit::alert intent="success">{{ $notice }}</x-wirekit::alert>
@endif
Livewire inserts such an alert together with its text, and a screen reader announces reliably only text that appears in a region already on the page. WireKit's script keeps one polite status region on the page and says the intent, the title and the message of each polite alert a Livewire render adds, without its actions or its dismiss button. A danger alert is announced by its own role="alert", and an alert inside a status region of the page's own is left to that region, so neither is said twice. Two alerts of one render that say the same, such as a notice at the top of the page and one beside the button that saved, are said once. An alert rendered with the page says nothing when the page loads.
Out of View
An alert often stands at the top of the page while the reader saved something far below it. With
toast-when-hidden, an alert that a Livewire render adds wholly above or below the window shows its
title and message as a toast as well, in the toast's color for the alert's
intent. The alert stays where it stands, and a screen reader hears it once: the toast says nothing
of what the alert says already. It needs a toast region on the page.
{{-- 1. The alert shows as a toast as well when it lands out of view --}}
@if ($notice !== null)
<x-wirekit::alert intent="success" toast-when-hidden>{{ $notice }}</x-wirekit::alert>
@endif
{{-- 2. Once per layout, for the toast to stand in --}}
<x-wirekit::toast-region />
Turn it on for every alert with toast-when-hidden in the alert entry of
config/, and off for one alert with :toast-when-hidden="false".
Props
| Prop | Type | Default | Description |
|---|---|---|---|
variant |
string | 'info' |
primary, neutral, info, success, warning, danger. primary tints with --color-wk-accent and info with --color-wk-info-tone, which is the accent until you give info a color of its own; neutral is a quiet gray treatment for non-severity-bearing notices. See Variants & Intents for the cross-component reference. |
intent |
string|null | null |
Canonical name for the color axis — the same spelling Button and Badge use: primary, neutral, info, success, warning, danger. Falls back to variant when omitted, and wins over it when both are given. |
title |
string|null | null |
Optional bold title above the body |
level |
int|null | null |
Makes the title a heading of this level, 1 to 6, in the alert's own size. Null keeps it a div |
dismissible |
bool | false |
Show a close button that hides the alert |
icon |
bool | true |
Whether to render the default intent icon |
toastWhenHidden |
bool | false |
Shows the title and message as a toast as well when a render adds the alert out of view. The default comes from toast-when-hidden in the configuration. See Out of View |
animateIn |
string|null | null |
Entrance-reveal preset (e.g. 'fade', 'slide-up', 'scale-in') — inline alternative to wrapping in <x-wirekit::reveal>. See Animations for the full preset list. Respects prefers-reduced-motion: reduce. |
scope |
string|null | null |
Scoped personalization name |
Slots
| Slot | Description |
|---|---|
| Default | Body text content |
title |
Bold heading above the body |
actions |
Action buttons/links below the body |
iconSlot |
Custom icon that overrides the intent-derived default icon |
Accessibility
- Role:
dangeralerts userole="alert"(assertive announcement). All other intents userole="status"(polite). - Added by a render: a polite alert a Livewire render adds is said by one status region of the page, which is there before it arrives (see After an Action).
- Screen reader prefix: Each alert starts with a visually hidden intent label (
"Warning: ...","Error: ...") so the intent is announced even without visual context. - Title: a heading of its
levelwhen one is given, adivwithout it. - Icons are decorative — marked
aria-hidden="true"since the meaning is conveyed by the text. - Dismiss button has
aria-label="Dismiss"and visible focus ring.
Keyboard Interaction
With dismissible, the alert renders a real <button>: it takes Tab focus, shows the focus ring, and Enter / Space dismiss it. The focus then moves to the next control after the alert (or the last one before it), so the next Tab continues from where the alert was. Actions placed in the alert are ordinary focusable controls in source order. A plain alert has no interactive element.
Pitfalls
- Don't use an alert as a permanent UI element. Alerts are status messages — for persistent banners, use
<x-wirekit::. The semantic difference matters for screen readers.callout> - Don't show ten alerts at once. Each
dangeralert is announced at once, and several arriving together interrupt one another, so a screen reader user hears fragments. Group related warnings into a single alert with a list, or use<x-wirekit::for transient notifications.toast-region>
Design Tokens
| Token | Purpose |
|---|---|
--color-wk-accent / --color-wk-accent-text |
primary intent border tint / icon |
--color-wk-info-tone / --color-wk-info-text |
info intent border tint / icon |
--color-wk-success / --color-wk-success-text |
success intent border tint / icon |
--color-wk-warning / --color-wk-warning-text |
warning intent border tint / icon |
--color-wk-danger / --color-wk-danger-text |
danger intent border tint / icon |
--color-wk-bg-elevated |
Base background mixed into intent tint |
--color-wk-text / --color-wk-text-muted |
Title / body text |
--radius-wk-md |
Corner radius |
Backgrounds are built with color-mix() — a 10% mix of the intent color into the elevated background. This keeps tints visually consistent across themes.
Customization
Override the default variant in config/:
'components' => [
'alert' => ['variant' => 'warning'],
],
Usage & Conventions
Prop conventions — this component uses one or more of the shared semantic prop names (
intent/variant/tone/surface). See Prop naming conventions for the canonical vocabulary, alias matrix, and decision tree.