Alert
A box with an icon, a title and a description that draws attention to a message in the page. It stays where it is until the page changes.
Thymeleaf source
<sl:alert> <sl:icon name="circle-check"/> <sl:alert-title>Order placed</sl:alert-title> <sl:alert-description>We will email you when it ships.</sl:alert-description></sl:alert>Rendered HTML
<div class="alert"> <svg xmlns="http://www.w3.org/2000/svg" class="icon" viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"> <circle cx="12" cy="12" r="10"></circle> <path d="m16 9-5.5 5.5L8 12"></path> </svg> <div class="alert-title">Order placed</div> <div class="alert-description">We will email you when it ships.</div></div>When to use
Section titled “When to use”- An error the server reports, such as data that could not be loaded.
- A notice, such as a trial that ends soon or a feature in beta.
- A warning above a form, such as a change that affects every user.
Use something else for:
- A short message about what just happened, that goes away by itself: a toast.
- Errors that belong to a whole form: form errors.
- A question the user must answer: an alert dialog.
Built from parts
Section titled “Built from parts”<sl:alert> holds an optional <sl:icon>, then <sl:alert-title> and <sl:alert-description>. The icon
takes the alert’s colour and sits beside both. Use either part on its own.
Thymeleaf source
<sl:alert> <sl:alert-title>Your trial ends in 3 days.</sl:alert-title></sl:alert>Rendered HTML
<div class="alert"> <div class="alert-title">Your trial ends in 3 days.</div></div>Destructive
Section titled “Destructive”Thymeleaf source
<sl:alert variant="destructive"> <sl:icon name="circle-alert"/> <sl:alert-title>Payment failed</sl:alert-title> <sl:alert-description> <p>Your card was declined. Check the details and try again:</p> <ul> <li>the expiry date</li> <li>the billing address</li> </ul> </sl:alert-description></sl:alert>Rendered HTML
<div class="alert" data-variant="destructive"> <svg xmlns="http://www.w3.org/2000/svg" class="icon" viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"> <circle cx="12" cy="12" r="10"></circle> <line x1="12" x2="12" y1="8" y2="12"></line> <line x1="12" x2="12.01" y1="16" y2="16"></line> </svg> <div class="alert-title">Payment failed</div> <div class="alert-description"> <p>Your card was declined. Check the details and try again:</p> <ul> <li>the expiry date</li> <li>the billing address</li> </ul> </div></div>Status variants
Section titled “Status variants”success, info and warning are Shadleaf’s own, for an order that shipped, a notice or a limit that is close. As the
destructive alert, they colour the text, the icon and the description: in --success-text, --info-text and
--warning-text, the same tokens as a toast’s rich colours, which keep 4.5:1 or more on the
card background in light and dark mode.
Thymeleaf source
<sl:alert variant="success"> <sl:icon name="circle-check"/> <sl:alert-title>Order shipped</sl:alert-title> <sl:alert-description>It should arrive on Thursday.</sl:alert-description></sl:alert><sl:alert variant="info"> <sl:icon name="info"/> <sl:alert-title>New invoices are monthly</sl:alert-title> <sl:alert-description>From January, you get one invoice per month instead of one per order.</sl:alert-description></sl:alert><sl:alert variant="warning"> <sl:icon name="triangle-alert"/> <sl:alert-title>Storage almost full</sl:alert-title> <sl:alert-description>You have used 90% of your storage. Delete old files or upgrade your plan.</sl:alert-description></sl:alert>Rendered HTML
<div class="alert" data-variant="success"> <svg xmlns="http://www.w3.org/2000/svg" class="icon" viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"> <circle cx="12" cy="12" r="10"></circle> <path d="m16 9-5.5 5.5L8 12"></path> </svg> <div class="alert-title">Order shipped</div> <div class="alert-description">It should arrive on Thursday.</div></div><div class="alert" data-variant="info"> <svg xmlns="http://www.w3.org/2000/svg" class="icon" viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"> <circle cx="12" cy="12" r="10"></circle> <path d="M12 16v-4"></path> <path d="M12 8h.01"></path> </svg> <div class="alert-title">New invoices are monthly</div> <div class="alert-description">From January, you get one invoice per month instead of one per order.</div></div><div class="alert" data-variant="warning"> <svg xmlns="http://www.w3.org/2000/svg" class="icon" viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"> <path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3"></path> <path d="M12 9v4"></path> <path d="M12 17h.01"></path> </svg> <div class="alert-title">Storage almost full</div> <div class="alert-description">You have used 90% of your storage. Delete old files or upgrade your plan.</div></div>Announcing an alert
Section titled “Announcing an alert”An alert is not announced by itself. Most alerts are part of the page when it loads, and a screen reader reads them in order with everything else; announcing them too would interrupt the user for no reason.
When an alert appears later, for example in the response to an htmx request, add role="alert". A screen reader then
reads it as soon as it is inserted. Like any other attribute, role passes through to the rendered element. An
alert that takes the focus when it appears (tabindex="-1" and autofocus, which htmx honours in swapped content) is
read out because of the focus, and needs no role; see Forms with htmx.
Thymeleaf source
<sl:alert variant="destructive" role="alert"> <sl:icon name="circle-alert"/> <sl:alert-title>The order could not be saved</sl:alert-title> <sl:alert-description>Someone else changed it. Reload the page to see their changes.</sl:alert-description></sl:alert>Rendered HTML
<div class="alert" data-variant="destructive" role="alert"> <svg xmlns="http://www.w3.org/2000/svg" class="icon" viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"> <circle cx="12" cy="12" r="10"></circle> <line x1="12" x2="12" y1="8" y2="12"></line> <line x1="12" x2="12.01" y1="16" y2="16"></line> </svg> <div class="alert-title">The order could not be saved</div> <div class="alert-description">Someone else changed it. Reload the page to see their changes.</div></div>For a message that is not urgent, role="status" is announced when the user is idle instead of at once.
Attributes
Section titled “Attributes”sl:alert
Section titled “sl:alert”| Attribute | Values | Default | Description |
|---|---|---|---|
variant | default destructive success info warning | default | Visual style of the alert. success, info and warning are Shadleaf's own, in the status colours. |
Every prop can also be set from an expression: th:variant="${...}". Any other attribute passes through to the rendered element, and class is appended.
sl:alert-title
Section titled “sl:alert-title”| Attribute | Values | Default | Description |
|---|---|---|---|
level | 1 2 3 4 5 6 | — | Heading level. With it the title is a heading (role="heading" and aria-level) that screen reader users can jump to; without it, plain text. |
Every prop can also be set from an expression: th:level="${...}". Any other attribute passes through to the rendered element, and class is appended.
sl:alert-description
Section titled “sl:alert-description”sl:alert-description declares no props; every attribute passes through.
Styling hooks
Section titled “Styling hooks”The classes and attributes your own CSS can select to restyle the component, as explained in your own CSS rules.
sl:alert
Section titled “sl:alert”Parts
| Class | Element |
|---|---|
.alert | <div> |
Props
| Prop | Selector | Values |
|---|---|---|
variant | .alert[data-variant="…"].alert:not([data-variant]) | destructive success info warningdefault (default) |
sl:alert-title
Section titled “sl:alert-title”Parts
| Class | Element |
|---|---|
.alert-title | <div> |
sl:alert-description
Section titled “sl:alert-description”Parts
| Class | Element |
|---|---|
.alert-description | <div> |