Native Web Components playground

Nova v3.37.0

Preview

Web Components

Alert

nv-alert

A persistent in-page message that shows feedback or a status people need to act on.

Live demo

Feedback

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.

The parts of an alert.
  1. Container takes its colours from feedback.
  2. Icon matches the feedback type. Use icon to choose another one.
  3. Title (heading) sums up the message in a few words.
  4. Message (message) gives the detail. The default slot can hold further content.
  5. Close button (optional, dismissible) hides the alert.
  6. Actions (optional, actions slot) 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.

FeedbackUse it for
informationHelpful guidance or details without urgency
warningA potential problem that needs attention
successConfirmation that an action completed
errorA problem the user needs to resolve
neutralGeneral context without an urgent action
information · default
success
warning
error
neutral

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.

secondary and primary
primary only
two secondary actions

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.
DoState the problem and what to do next.
Don'tAvoid vague, emotional messages and excessive punctuation.

Sources