Notification
- Theme Variants
- Duration
- Position
- Stacking
- Size
- Interactive Elements
- Icons and Other Rich Formatting
- Static Helper
- Best Practices
- Related Components
Notifications are used to provide feedback to the user. They communicate information about activities, processes, and events in the application.
new tab
Source code
notification-basic-preview.ts
notification-basic-preview.ts
Theme Variants
Success
The success
theme variant can be used to display success messages, such as when a task or operation is completed.
new tab
Source code
notification-success-preview.ts
notification-success-preview.ts
Successful operations shouldn’t routinely be declared using notifications, as these can be more distracting than useful for the user. Use success notifications only for operations whose successful completion may otherwise be difficult to discern.
Error
The error
theme variant can be used to display alerts, failures, or warnings.
new tab
Source code
notification-error-preview.ts
notification-error-preview.ts
Error notifications should be persistent, and provide the user with a button that closes the notification and/or allows the user to take appropriate action.
Notifications are non-modal and can be ignored, making them inappropriate for displaying unexpected technical errors that prevent the application from functioning, or situations that require immediate user action. Use a modal Dialog in such situations.
Primary
The primary
theme variant can be used for important informational messages and/or to draw extra attention to a notification.
new tab
Source code
notification-primary-preview.ts
notification-primary-preview.ts
Contrast
A high-contrast version that improves legibility and distinguishes the notification from the rest of the UI.
new tab
Source code
notification-contrast-preview.ts
notification-contrast-preview.ts
Duration
By default, notifications stay on-screen for 5 seconds. The duration is in milliseconds, and should be based on content and importance:
Use short durations for notifications that have:
-
short text content
-
lesser importance (for example, operations that finished without errors)
-
no interactive elements
Use longer durations for notifications that have:
-
longer text content
-
higher importance (for example, errors)
-
interactive elements (for example, links or "undo" actions)
A duration of at least 5 seconds is recommended to ensure that the user has a chance to see and understand the notification.
Persistent Notifications
Setting the duration to zero disables auto-closing, keeping the notification visible until explicitly dismissed by the user. This should be used for notifications that provide vital information to the user, such as errors. Persistent notifications should contain a Button that closes the notification and/or allows the user to take appropriate action.
Less-important notifications shouldn’t be persistent, and instead disappear automatically after an appropriate delay.
Position
Notifications can be positioned in the viewport in seven non-stretched positions, or stretched across the top or bottom:
new tab
Use the position
attribute in HTML templates, for example <vaadin-notification position="top-end"></vaadin-notification>
.
Source code
notification-position.ts
notification-position-example.css
NotificationPosition.java
notification-position-example.css
Recommendations
-
Top End or Bottom Start are recommended for most notifications, as these are unobtrusive, but still noticeable.
-
Middle is the most disruptive position, and should be used only for important notifications, such as errors.
-
Bottom End is the least obtrusive position, but can go unnoticed.
-
Stretch notifications, which span the full width of the viewport, are more disruptive, and should be reserved for important notifications whose contents require more space.
-
Applications with a notification button or drop-down in the header or footer should position notifications to appear in the same part of the screen.
-
For a consistent user experience, use one or two positions throughout the application.
-
Avoid using positions that may obstruct important parts of the UI, such as navigation.
Note
|
The Flow styling issue
The Flow notification component renders rich content via an intermediate Source codeCSS
|
Stacking
Multiple simultaneously displayed notifications are stacked vertically, depending on their positioning:
-
When using the bottom half of the screen as the position, a new notification appears below the older notifications.
-
With the position set to the top half, a new notification appears above the existing notifications.
Size
The notification card is automatically sized based on its content.
-
In large viewports, the card’s maximum width is one-third of the viewport.
-
In small viewports, the card always takes up the entire width of the viewport.
Interactive Elements
Notifications can contain interactive content, such as Buttons or links that allow the user to perform related actions.
For example, if an operation fails, the error notification could offer the user the opportunity to try again. Or it could contain a link to a view that allows the user to resolve the problem.
new tab
Source code
notification-retry-preview.ts
notification-retry-preview.ts
In situations where the user might want to revert an action, display an "undo" button.
new tab
Source code
notification-undo-preview.ts
notification-undo-preview.ts
Notifications can also contain links to relevant information.
new tab
Source code
notification-link-preview.ts
notification-link-preview.ts
Making Interactive Elements Keyboard-Accessible
Take care to ensure that keyboard-only users can access interactive elements in notifications:
-
Make the notification persistent, to prevent it from disappearing before the user has had a chance to interact with it.
-
Provide a keyboard shortcut, either to trigger the action itself, or to move focus to the notification card in cases where multiple interactive elements are present.
-
Make the shortcut discoverable, for example by displaying it as part of the notification’s content.
new tab
Source code
notification-keyboard-a11y-preview.ts
notification-keyboard-a11y-preview.ts
Icons and Other Rich Formatting
Icons and other content formatting can be used to provide information and helpful visual cues, for example to make errors and success notifications easier to distinguish for users with color blindness.
new tab
Source code
notification-rich-preview.ts
notification-rich-preview.ts
Static Helper
For simple, one-off notifications, it’s convenient to use the static show()
helper method.
The helper manages the notification’s lifecycle, and adds and removes it from the DOM automatically.
Best Practices
Use Sparingly
Notifications are disruptive by design and should be used sparingly. Use fewer notifications by reserving them for more-important information that might otherwise go unnoticed by the user.
Less-urgent notifications can be provided through a link or drop-down in the application header or footer, instead of via immediate notifications.
Limit Content Length
Aim for one or two lines of content. Notifications should be brief and to the point. More information can be provided through an embedded link or Button.
new tab
Source code
notification-content-length-do.ts
notification-content-length-do.ts
new tab