Skip to content

Alert

A box that says something about the whole: that the application was sent, that the service is down, that the deadline is approaching. If the message is about one field, it belongs under the field as an Error Text or a Help Text.

data-colorUsed for
(omitted)Neutral information
infoSomething the user should know, but that needs no action
successSomething went well
warningSomething needs attention, but stops nothing
dangerSomething went wrong, or stops the user

The role is not part of data-color, because it depends on when the message appears, not on what it means.

SituationWhat you set
The message is in the markup when the page loadsNo role
The message appears while the user is workingrole="status"
The user has to stop and do something nowrole="alert"
<div class="lt-alert" data-color="danger" role="alert">
<p class="lt-alert__title">Your application was not sent</p>
<p>The network did not respond. Try again in a moment.</p>
</div>

role="alert" interrupts what the screen reader is doing. Use it only when the interruption is justified. role="status" waits until the user has finished their sentence.

The element must be in the DOM before you fill it with text. If you insert the whole box already filled in, the screen reader does not notice the change.

ClassWhat it is
.lt-alertThe box itself. The colour comes from data-color.
.lt-alert__titleThe heading inside the box
VariableDefault
--lt-alert-paddingvar(--lt-spacing-3) var(--lt-spacing-4)
--lt-alert-radiusvar(--lt-spacing-1)
--lt-alert-accentvar(--lt-spacing-1), the width of the stripe along the edge

Each colour has a stripe on the edge and a faint surface behind the text, and the body text keeps its contrast against that surface in both themes. See Customising.

  • The colour alone says nothing. The text must carry the message for someone who cannot tell green from red as well.
  • One message at a time. Three boxes on top of each other read as noise, and the user cannot find the one that matters.
  • Say what the user should do. “Try again in a moment” helps where “An error occurred” does not.
  • If the message can be closed, give the close button a text that says what is being closed, not just a cross.