Alert - National Design System

Alert notifications for displaying important messages, warnings, and feedback to users

Variants

Five status variants communicate different message types through color and icon

Inline

Compact single-line layout with bottom stripe and solid icon

With Actions

Action buttons let users respond directly from the notification

Toast Notifications

Floating notifications that appear at the top or bottom of the viewport

Select a variant and position above, then click the button to preview

Built-in Features

Auto-initialization

Activates when .nds-alert is on the page. Close button handlers attach automatically.

Six Status Variants

Success, info, warning, error, critical, and neutral with automatic icon and color theming.

Toast Notifications

Fixed positioning with auto-dismiss timer and progress indicator.

Inline Layout

Single-line variant for contextual messages with actions pushed to the end.

Programmatic Control

Create, dismiss, and bulk-clear alerts through the JS API without writing HTML.

Responsive Layout

Stacks vertically on mobile with stripe repositioned to the top.

Usage Guidelines

Best Practices

  • Use standard alerts for important messages that need a title and description within a page section
  • Use inline alerts for contextual feedback near a form field or action where space is limited
  • Use toast notifications for transient feedback after an action (save, delete, submit) that does not require the user to stay on the page
  • Choose the variant that matches the message severity: success for confirmations, info for neutral updates, warning for caution, error for failures, critical for system-level emergencies, neutral for general notices
  • Do not use alerts for blocking decisions that require user input. Use a Modal instead
  • Do not use toast notifications for critical errors or messages that require user action. Toasts can auto-dismiss before the user reads them
  • Prefer alerts over modals for non-blocking feedback. Alerts let users continue working without interruption
  • Add action buttons when the user needs to respond (retry, undo, update) rather than just acknowledge the message
  • Add nds-color to reinforce severity in high-density layouts where the stripe alone may not stand out
  • Keep alert descriptions to one or two sentences. For longer content, link to a detail page with an action link
  • Set a reasonable duration for toast notifications (3000-5000 ms). Avoid durations under 2000 ms as users may not have time to read the message

Modifier Classes

ClassDescription
nds-inlineCompact single-line layout with bottom stripe and solid icon
nds-toastFloating notification style with opacity transitions for toast display
nds-shadowAdds elevation shadow to the alert card
nds-colorApplies a tinted background matching the status variant

Data Attributes

AttributeDescription
data-statusSet on .nds-alert to control the variant. Values: success, info, warning, error, critical, neutral
data-positionSet on .nds-alert-placeholder to position toast containers. Values: top, bottom
data-toast-stateControls toast visibility transitions. Values: show, hide. Managed automatically by the JS API

CSS Custom Properties

PropertyDefaultDescription
--alert-stripe--border-neutral-primaryColor of the side stripe indicator
--alert-icon-bg--background-neutral-lightBackground color of the feedback icon circle

JavaScript API

The NDS.Alert API provides methods to create, display, and dismiss alerts programmatically. For dynamically added HTML alerts, call NDS.Alert.init() to re-attach close button handlers.

// ── Create an alert ────────────────────────────────── // Returns the created HTMLElement const alert = NDS.Alert.create({ variant: 'success', // 'success' | 'warning' | 'error' | 'critical' | 'info' | 'neutral' title: 'Success', // Optional heading text description: 'Saved.', // Alert body text target: '#container', // CSS selector or DOM element to insert into closable: true, // Show close button (default: true) shadow: false, // Add nds-shadow class (default: false) color: false, // Add nds-color background (default: false) id: 'my-alert', // Custom element ID (optional) prepend: false, // Insert at start of target (default: false) display: 'default', // 'default' | 'inline' | 'toast' actions: [ // Action buttons (optional) { label: 'Retry', class: 'nds-btn nds-primary nds-sm', // Custom classes (overrides variant/size) onClick: (el) => {}, // Callback, receives the alert element dismiss: false, // Auto-dismiss after click (default: false) href: '/url', // Render as <a> link instead of <button> (optional) target: '_blank' // Link target attribute (optional, requires href) } ] }); // ── Create a toast notification ────────────────────── NDS.Alert.create({ variant: 'success', description: 'Changes saved!', display: 'toast', // 'default' | 'inline' | 'toast' position: 'top', // 'top' | 'bottom' (default: 'top') duration: 4000, // Auto-dismiss in ms, 0 = manual (default: 0) shadow: true }); // ── Dismiss ────────────────────────────────────────── NDS.Alert.dismiss(alert); // By element reference NDS.Alert.dismiss('#my-alert'); // By selector NDS.Alert.dismissAll('#container'); // All alerts in a container NDS.Alert.dismissAll(document.body); // All alerts on page // ── Re-initialize after dynamic HTML ───────────────── // Attaches close handlers to any new .nds-alert elements NDS.Alert.init();
Was this page useful?
60% of users said Yes from 2843 Feedbacks