Alert
Inline messages. Flat; give them a color with alert-amber, alert-red… and a strength like alert-subtle if you like.
<div class="alert alert-green alert-subtle" role="status">
<i class="mi mi-circle-check alert-icon"></i>
<div class="alert-content">Your changes were saved.</div>
</div>
Title, actions and dismiss
Add a payment method to keep your workspace and all your data.
- Email is required
- Password must be at least 8 characters
- Choose a plan
<div class="alert alert-amber alert-subtle" role="status">
<i class="mi mi-triangle-alert alert-icon"></i>
<div class="alert-content">
<div class="alert-title">Your trial ends in 3 days</div>
<p>Add a payment method to keep your workspace.</p>
<div class="alert-actions">…buttons…</div>
</div>
<button class="btn-close" aria-label="Dismiss"></button>
</div>
The close button takes the alert's color automatically, and with moey.js included it just works — click it and the alert fades out. No extra attributes.
<script src="dist/moey.js" defer></script>
<!-- Any other button can close it too -->
<button class="btn btn-ghost btn-sm" data-moey-dismiss>Remind me later</button>
<button data-moey-dismiss="#promo">Hide the promo</button>
// React to it
alert.addEventListener('moey:close', e => { if (unsaved) e.preventDefault(); }); // cancel
document.addEventListener('moey:closed', e => console.log('removed', e.detail.element));
// Or from code
Moey.dismiss(document.querySelector('#my-alert'));
.alert-instant skips the fade.
Plain text and dividers
Text can go straight inside an alert — the close button pins itself to the top-right. A <hr> inside takes the alert's color.
You successfully read this important message.
Use a divider to separate extra details.
<div class="alert alert-amber alert-subtle" role="status">
<strong>Heads up!</strong> Plain text with a <a href="#">link</a>.
<button class="btn-close" aria-label="Close"></button>
</div>
Solid, outline, small and banner
| Class | Use it for |
|---|---|
.alert-<color> + .alert-subtle | Most messages — a light tint |
.alert-<color> alone · .alert-soft | A bit more color (the soft default fill · a light fill) |
.alert-solid · .alert-vivid · .alert-deep | Critical, must-see messages — the full color, stronger, darkest |
.alert-outline | Quieter messages inside busy pages |
.alert-sm | Compact inline messages (forms, cards) |
.alert-banner | Full-width bar at the top of a page or app |
Accessibility: use role="alert" for urgent messages that appear while someone works (errors) — screen readers announce them immediately. Use role="status" for everything else.
Strengths
Every alert color comes in the same strengths as buttons — from a whisper to a shout.
alert-green alert-subtlealert-green alert-softalert-greenalert-green alert-solidalert-green alert-vividalert-green alert-deep<div class="alert alert-green alert-subtle">…</div> <!-- lightest -->
<div class="alert alert-green">…</div> <!-- the soft default fill -->
<div class="alert alert-green alert-vivid">…</div>
<div class="alert alert-green alert-deep">…</div> <!-- darkest -->
Colors
<div class="alert alert-amber alert-subtle">…</div>
Form error summary
Above a form after a failed submit — role="alert" so it is announced right away.
<div class="alert alert-red alert-subtle max-w-lg" role="alert">
<i class="mi mi-circle-x alert-icon"></i>
<div class="alert-content"><div class="alert-title">2 fields need attention</div>
<ul class="mt-1 mb-0 mx-0 ps-4">
<li><a href="#alert">Email</a> is not a valid address</li>
<li><a href="#alert">Password</a> must be at least 8 characters</li>
</ul>
</div>
</div>
Inside a card
Your next payout is scheduled for Monday.
<div class="card"><div class="card-header"><div class="card-title">Payouts</div></div><div class="card-body grid grid-cols-1 gap-4">
<div class="alert alert-amber alert-subtle alert-sm" role="status">
<i class="mi mi-triangle-alert alert-icon"></i>
<div class="alert-content">
Add a bank account to receive payouts.
<a href="#alert">Add account</a>
</div>
</div>
<p class="m-0 text-subtle">Your next payout is scheduled for Monday.</p>
</div></div>
Every theme
<div class="alert alert-green alert-subtle" role="status">
<i class="mi mi-circle-check alert-icon"></i>
<div class="alert-content">Success — it worked.</div>
</div>