Live demo
Demo source
Use an alert for an important message that belongs to the page, such as an error that blocks a task or a warning before people continue. Alerts stay until people dismiss them or fix the problem. For a short, timed message about something that just happened, use a notification instead.
Anatomy
A blue information alert with six callouts: 1 marks the container, 2 the information icon, 3 the title Alert title, 4 the message below it, 5 the close button, and 6 the actions at the bottom right.
- Container takes its colours from
feedback. - Icon matches the feedback type. Use
iconto choose another one. - Title (
heading) sums up the message in a few words. - Message (
message) gives the detail. The default slot can hold further content. - Close button (optional,
dismissible) hides the alert. - Actions (optional,
actionsslot) let people act on the message.
Feedback types
feedback sets one of five types: information (the default), success,
warning, error and neutral. Match the type to the severity, and always
pair the colour with a clear title, because colour alone doesn't carry the
meaning.
| Feedback | Use it for |
|---|---|
information | Helpful guidance or details without urgency |
warning | A potential problem that needs attention |
success | Confirmation that an action completed |
error | A problem the user needs to resolve |
neutral | General context without an urgent action |
Actions
Use the actions slot when people can act on the alert where it appears. Wrap
the actions in one element that gets the slot. They sit below the content,
aligned to the right, and wrap to a new line when space is missing.
The last action is primary and follows the feedback colour. The actions before
it are secondary and stay neutral. To change that,
data-action="primary" or data-action="secondary" forces the role of an
action and wins over its position. Up to three actions are supported, and two
are recommended.
The alert sets the look of its actions, whatever you put in the slot: a link, a
button or an nv-button. Any size, emphasis, colour, border or background you
set is overridden. On hover, the label is underlined and the colours stay the
same. An icon before or after the label takes the size and colour of the action.
Use disabled, or aria-disabled="true" on a link, to disable an action. A
link with aria-disabled="true" only looks disabled, so stop its navigation in
your own code.
The alert emits no events for its actions and doesn't dismiss itself when one is used. Use a link for navigation, and handle clicks on your own elements. An alert is announced to screen readers without moving focus, so the actions shouldn't be the only way to complete an urgent task.
Dismissal and custom content
Alerts have no dismissal timer. Set dismissible for messages people can
close; clicking the close button sets hidden and emits closeClicked.
With preventAutoClose, your application decides when to hide it instead.
Keep critical information visible while it is still needed.
Use heading and message for simple text, and the default slot for richer
content. Feedback colours and icons follow Spark or
Ocean in light and dark modes. Keep the icon and message together so the
feedback remains understandable without colour. The component exposes
role="alert"; actions still need clear labels and keyboard access.
Content
- State the problem clearly and say what to do next.
- Keep the message under two sentences, without emotional language or excessive punctuation.
- Don't let people dismiss a critical alert while the information is still needed.