Alert

A callout for a message the reader should not miss.

Feedback Added in v0.41.0 Updated

Default


{ui alert,
	title: 'Heads up',
	description: 'An alert with an icon, a title and a description.',
	icon: 'info',
/}

An alert is drawn with role="alert", so a screen reader announces it when it appears. That suits a message swapped in by HTMX after a save, and is too loud for static page text: use a card there.

Destructive


{ui alert,
	title: 'Something went wrong',
	description: 'The destructive variant.',
	icon: 'circle-alert',
	class: 'alert-destructive',
/}

Success, warning and info


<div class="flex flex-col gap-4">
	{ui alert,
		title: 'Saved',
		description: 'The success variant.',
		icon: 'circle-check',
		class: 'alert-success',
	/}
	{ui alert,
		title: 'Heads up',
		description: 'The warning variant.',
		icon: 'triangle-alert',
		class: 'alert-warning',
	/}
	{ui alert,
		title: 'New version',
		description: 'The info variant.',
		icon: 'info',
		class: 'alert-info',
	/}
</div>

Each tone class (alert-success, alert-warning, alert-info, alert-destructive) tints the background and border and colours the text and icon with its token, so a flash message after a save can say how it went. Pick the class on the server and return the alert as the swapped-in fragment.

Title only


{ui alert, title: 'Saved', icon: 'check' /}

Title and description are both optional. The icon takes the alert's text colour.

Content and action


<div class="flex flex-col gap-4">
	{ui alert,
		title: 'Trial ends soon',
		icon: 'triangle-alert',
		class: 'alert-warning',
	}
		<p>Add a card to keep your projects.</p>
		{block action}
			{ui button, title: 'Upgrade' /}
		{/block}
	{/ui}
	{ui alert,
		title: 'Saved',
		icon: 'circle-check',
		class: 'alert-success',
	}
		{block action}
			{ui button,
				class: 'button-ghost button-icon',
				icon: 'x',
				attrs: [
					'aria-label' => 'Dismiss',
					'hx-on:click' => "this.closest('[role=alert]').remove()",
				],
			/}
		{/block}
	{/ui}
</div>

Written as a pair, {ui alert}...{/ui} takes its content in place of the description, so it can hold more than one line of markup. Write it as a <p>: the muted colour is set on the alert's paragraphs. {block action} fills a trailing slot on the right, for a button or link, and the slot is left out when it is empty. action also takes a string.

There is no close param. A dismissible alert is a ghost icon button in the action slot with an hx-on:click that removes the alert, so the state stays in the DOM.

Own heading


{ui alert, icon: 'info', class: 'alert-info'}
	{block heading}
		<h2>Maintenance on <time datetime="2026-11-20">20 November</time></h2>
	{/block}
	<p>The site is read only for an hour from 02:00.</p>
{/ui}

{block heading} replaces the title line, for a heading that holds markup such as a date or a link. Keep it an h2 so it takes the bold first-line style.