Light themes
Dark themes

Make your own

Alert

An alert is a message that stays in the page until its cause is gone: a tray row with an icon tile, a title and a sentence.

The farm shop is closed on Mondays

Pickup orders placed today are ready from Tuesday at ten.

Order PL-20418 is paid

The receipt is on its way to dana@example.com.

132 jars of the autumn batch are left

The next batch is packed in March.

Playground

An alert that stays in the page: its tone, its words and whether it offers a way out.

HTML

Variants

ClassUse
tray-alertNeutral information.
tray-alert tray-alert--dangerSomething failed and needs the person: the icon and title turn danger.
tray-alert tray-alert--successA finished step that is worth confirming in place.
tray-alert tray-alert--accentThe one thing to act on now. It is a yellow surface, so one per screen.

Markup

HTML
<div class="tray-alert tray-alert--danger" role="alert">
  <span class="tray-alert__icon">…icon…</span>
  <div class="tray-alert__body">
    <p class="tray-alert__title">The card was declined</p>
    <p class="tray-alert__text">Try another card, or pay on delivery.</p>
    <div class="tray-alert__actions">…buttons…</div>
  </div>
</div>

Use role="alert" for an error that appears after an action and role="status" for the rest.

Alert, Toast or Field error

An alert belongs to a page or a card and stays. A Toast confirms something that already happened and leaves by itself. An error about one field goes under that field.

Accessibility

role="alert" makes a screen reader read the alert at once when it appears, and role="status" makes it wait until the reader is free. The icon is decoration, so keep its <svg> aria-hidden: the title says what happened, and the danger and success colours only repeat it. The alert never takes focus, and the buttons in tray-alert__actions wait in the normal tab order.

Do and don't

  • Do say what happened and what to do next, in that order.
  • Do keep the title to one line.
  • Don't stack more than two alerts; merge them.
  • Don't close an error alert on a timer.
↑↓ to moveEnter to openEsc to close