Docs

Documentation versions (currently viewingVaadin 14)

You are viewing documentation for an older Vaadin version. View latest documentation

Notification

Notifications are used to provide feedback to the user. They communicate information about activities, processes, and events in the application.

Open in a
new tab
import { html, LitElement } from 'lit-element';
import '@vaadin/vaadin-notification/vaadin-notification';
import { applyTheme } from 'Frontend/generated/theme';

export class Example extends LitElement {
  protected createRenderRoot() {
    const root = super.createRenderRoot();
    // Apply custom theme (only supported if your app uses one)
    applyTheme(root);
    return root;
  }

  render() {
    return html`
      <vaadin-notification-card slot="middle">
        Financial report generated
      </vaadin-notification-card>
    `;
  }
}
Open in a
new tab
// When creating a notification using the `show` static method,
// the duration is 5-sec by default.
Notification notification = Notification.show("Financial report generated");

Theme Variants

Success

The success theme variant can be used to display success messages, such as when a task or operation is completed.

Open in a
new tab
import { html, LitElement } from 'lit-element';
import '@vaadin/vaadin-notification/vaadin-notification';
import { applyTheme } from 'Frontend/generated/theme';

export class Example extends LitElement {
  protected createRenderRoot() {
    const root = super.createRenderRoot();
    // Apply custom theme (only supported if your app uses one)
    applyTheme(root);
    return root;
  }

  render() {
    return html`
      <vaadin-notification-card theme="success" slot="middle">
        Application submitted!
      </vaadin-notification-card>
    `;
  }
}
Open in a
new tab
Notification notification = Notification.show("Application submitted!");
notification.addThemeVariants(NotificationVariant.LUMO_SUCCESS);

Most successful operations should not be declared with notifications, as these can distract the user more than provide useful information. Only use success notifications 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.

Open in a
new tab
import { html, LitElement } from 'lit-element';
import '@vaadin/vaadin-lumo-styles/icons';
import '@vaadin/vaadin-button/vaadin-button';
import '@vaadin/vaadin-notification/vaadin-notification';
import '@vaadin/vaadin-ordered-layout/vaadin-horizontal-layout';
import { applyTheme } from 'Frontend/generated/theme';

export class Example extends LitElement {
  protected createRenderRoot() {
    const root = super.createRenderRoot();
    // Apply custom theme (only supported if your app uses one)
    applyTheme(root);
    return root;
  }

  render() {
    return html`
      <vaadin-notification-card theme="error" slot="middle">
        <vaadin-horizontal-layout theme="spacing" style="align-items: center;">
          <div>Failed to generate report</div>
          <vaadin-button theme="tertiary-inline">
            <iron-icon icon="lumo:cross"></iron-icon>
          </vaadin-button>
        </vaadin-horizontal-layout>
      </vaadin-notification-card>
    `;
  }
}
Open in a
new tab
// When creating a notification using the constructor,
// the duration is 0-sec by default which means that
// the notification does not close automatically.
Notification notification = new Notification();
notification.addThemeVariants(NotificationVariant.LUMO_ERROR);

Div text = new Div(new Text("Failed to generate report"));

Button closeButton = new Button(new Icon("lumo", "cross"));
closeButton.addThemeVariants(ButtonVariant.LUMO_TERTIARY_INLINE);
closeButton.getElement().setAttribute("aria-label", "Close");
closeButton.addClickListener(event -> {
  notification.close();
});

HorizontalLayout layout = new HorizontalLayout(text, closeButton);
layout.setAlignItems(Alignment.CENTER);

notification.add(layout);
notification.open();

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 it.

Open in a
new tab
import { html, LitElement } from 'lit-element';
import '@vaadin/vaadin-notification/vaadin-notification';
import { applyTheme } from 'Frontend/generated/theme';

export class Example extends LitElement {
  protected createRenderRoot() {
    const root = super.createRenderRoot();
    // Apply custom theme (only supported if your app uses one)
    applyTheme(root);
    return root;
  }

  render() {
    return html`
      <vaadin-notification-card theme="primary" slot="middle">
        New project plan available
      </vaadin-notification-card>
    `;
  }
}
Open in a
new tab
Notification notification = Notification.show("New project plan available");
notification.addThemeVariants(NotificationVariant.LUMO_PRIMARY);

Contrast

A high-contrast version that improves legibility and distinguishes it from the rest of the UI.

Open in a
new tab
import { html, LitElement } from 'lit-element';
import '@vaadin/vaadin-notification/vaadin-notification';
import { applyTheme } from 'Frontend/generated/theme';

export class Example extends LitElement {
  protected createRenderRoot() {
    const root = super.createRenderRoot();
    // Apply custom theme (only supported if your app uses one)
    applyTheme(root);
    return root;
  }

  render() {
    return html`
      <vaadin-notification-card theme="contrast" slot="middle">
        5 tasks deleted
      </vaadin-notification-card>
    `;
  }
}
Open in a
new tab
Notification notification = Notification.show("5 tasks deleted");
notification.addThemeVariants(NotificationVariant.LUMO_CONTRAST);

Duration

Notifications stay on-screen for 5 seconds by default. 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 should not 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:

Open in a
new tab
add(
  createButton(Position.TOP_STRETCH),
  createButton(Position.TOP_START),
  createButton(Position.TOP_CENTER),
  createButton(Position.TOP_END),
  createButton(Position.MIDDLE),
  createButton(Position.BOTTOM_START),
  createButton(Position.BOTTOM_CENTER),
  createButton(Position.BOTTOM_END),
  createButton(Position.BOTTOM_STRETCH)
);

...

private Button createButton(Position position) {
  Button button = new Button(position.getClientName());
  button.addClickListener(event -> show(position));
  return button;
}

...

private void show(Position position) {
  Notification.show(position.getClientName(), 5000, position);
}

Recommendations

  • Top End or Bottom Start are recommended for most notifications, as these are non-obtrusive but still noticeable.

  • Middle is the most disruptive position, and only be used for important notifications like errors.

  • Bottom End is the least obtrusive position, but can go unnoticed.

  • Stretch notifications, that 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 <flow-component-renderer> element. This can prevent notification content from using the full width, when using top stretch or bottom stretch positioning. To work around this issue, add the following CSS rule to a global style sheet:

vaadin-notification-card flow-component-renderer,
vaadin-notification-card flow-component-renderer > div {
  display: contents;
}

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 ⅓ of the viewport.

  • In small viewports, the card always takes up the entire width of the viewport.

Interactive Elements

Notifications can contain interactive content like 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 possibility to try again. Or, it could contain a link to a view that allows the user to resolve the problem.

Open in a
new tab
import { html, LitElement } from 'lit-element';
import '@vaadin/vaadin-lumo-styles/icons';
import '@vaadin/vaadin-button/vaadin-button';
import '@vaadin/vaadin-notification/vaadin-notification';
import '@vaadin/vaadin-ordered-layout/vaadin-horizontal-layout';
import { applyTheme } from 'Frontend/generated/theme';

export class Example extends LitElement {
  protected createRenderRoot() {
    const root = super.createRenderRoot();
    // Apply custom theme (only supported if your app uses one)
    applyTheme(root);
    return root;
  }

  render() {
    return html`
      <vaadin-notification-card theme="error" slot="middle">
        <vaadin-horizontal-layout theme="spacing" style="align-items: center;">
          <div>Failed to generate report</div>
          <vaadin-button theme="tertiary-inline" style="margin-left: var(--lumo-space-xl);">
            Retry
          </vaadin-button>
          <vaadin-button theme="tertiary-inline" aria-label="Close">
            <iron-icon icon="lumo:cross"></iron-icon>
          </vaadin-button>
        </vaadin-horizontal-layout>
      </vaadin-notification-card>
    `;
  }
}
Open in a
new tab
// When creating a notification using the constructor,
// the duration is 0-sec by default which means that
// the notification does not close automatically.
Notification notification = new Notification();
notification.addThemeVariants(NotificationVariant.LUMO_ERROR);

Div statusText = new Div(new Text("Failed to generate report"));

Button retryButton = new Button("Retry");
retryButton.addThemeVariants(ButtonVariant.LUMO_TERTIARY_INLINE);
retryButton.getElement().getStyle().set("margin-left", "var(--lumo-space-xl)");
retryButton.addClickListener(event -> {
  notification.close();
});

Button closeButton = new Button(new Icon("lumo", "cross"));
closeButton.addThemeVariants(ButtonVariant.LUMO_TERTIARY_INLINE);
closeButton.getElement().setAttribute("aria-label", "Close");
closeButton.addClickListener(event -> {
  notification.close();
});

HorizontalLayout layout = new HorizontalLayout(statusText, retryButton, closeButton);
layout.setAlignItems(Alignment.CENTER);

notification.add(layout);
notification.open();

In situations where the user might want to revert an action, display an Undo button.

Open in a
new tab
import { html, LitElement } from 'lit-element';
import '@vaadin/vaadin-lumo-styles/icons';
import '@vaadin/vaadin-button/vaadin-button';
import '@vaadin/vaadin-notification/vaadin-notification';
import '@vaadin/vaadin-ordered-layout/vaadin-horizontal-layout';
import { applyTheme } from 'Frontend/generated/theme';

export class Example extends LitElement {
  protected createRenderRoot() {
    const root = super.createRenderRoot();
    // Apply custom theme (only supported if your app uses one)
    applyTheme(root);
    return root;
  }

  render() {
    return html`
      <vaadin-notification-card theme="contrast" slot="middle">
        <vaadin-horizontal-layout theme="spacing" style="align-items: center;">
          <div>5 tasks deleted</div>
          <vaadin-button theme="tertiary-inline" style="margin-left: var(--lumo-space-xl);">
            Undo
          </vaadin-button>
          <vaadin-button theme="tertiary-inline" aria-label="Close">
            <iron-icon icon="lumo:cross"></iron-icon>
          </vaadin-button>
        </vaadin-horizontal-layout>
      </vaadin-notification-card>
    `;
  }
}
Open in a
new tab
Notification notification = new Notification();
notification.setDuration(10000);
notification.addThemeVariants(NotificationVariant.LUMO_CONTRAST);

Div statusText = new Div(new Text("5 tasks deleted"));

Button undoButton = new Button("Undo");
undoButton.addThemeVariants(ButtonVariant.LUMO_TERTIARY_INLINE);
undoButton.getElement().getStyle().set("margin-left", "var(--lumo-space-xl)");
undoButton.addClickListener(event -> {
  notification.close();
});

Button closeButton = new Button(new Icon("lumo", "cross"));
closeButton.addThemeVariants(ButtonVariant.LUMO_TERTIARY_INLINE);
closeButton.getElement().setAttribute("aria-label", "Close");
closeButton.addClickListener(event -> {
  notification.close();
});

HorizontalLayout layout = new HorizontalLayout(statusText, undoButton, closeButton);
layout.setAlignItems(Alignment.CENTER);

notification.add(layout);
notification.open();

Notifications can also contain links to relevant information.

Open in a
new tab
import { html, LitElement } from 'lit-element';
import '@vaadin/vaadin-lumo-styles/icons';
import '@vaadin/vaadin-button/vaadin-button';
import '@vaadin/vaadin-notification/vaadin-notification';
import '@vaadin/vaadin-ordered-layout/vaadin-horizontal-layout';
import { applyTheme } from 'Frontend/generated/theme';

export class Example extends LitElement {
  protected createRenderRoot() {
    const root = super.createRenderRoot();
    // Apply custom theme (only supported if your app uses one)
    applyTheme(root);
    return root;
  }

  render() {
    return html`
      <vaadin-notification-card slot="middle">
        <vaadin-horizontal-layout theme="spacing" style="align-items: center;">
          <div>Jason Bailey mentioned you in <a href="#">Project Q4</a></div>
          <vaadin-button theme="tertiary-inline">
            <iron-icon icon="lumo:cross"></iron-icon>
          </vaadin-button>
        </vaadin-horizontal-layout>
      </vaadin-notification-card>
    `;
  }
}
Open in a
new tab
// When creating a notification using the constructor,
// the duration is 0-sec by default which means that
// the notification does not close automatically.
Notification notification = new Notification();

Div text = new Div(
  new Text("Jason Bailey mentioned you in "),
  new Anchor("#", "Project Q4")
);

Button closeButton = new Button(new Icon("lumo", "cross"));
closeButton.addThemeVariants(ButtonVariant.LUMO_TERTIARY_INLINE);
closeButton.getElement().setAttribute("aria-label", "Close");
closeButton.addClickListener(event -> {
  notification.close();
});

HorizontalLayout layout = new HorizontalLayout(text, closeButton);
layout.setAlignItems(Alignment.CENTER);

notification.add(layout);
notification.open();

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.

Open in a
new tab
import { html, LitElement } from 'lit-element';
import '@vaadin/vaadin-button/vaadin-button';
import '@vaadin/vaadin-notification/vaadin-notification';
import '@vaadin/vaadin-ordered-layout/vaadin-horizontal-layout';
import { applyTheme } from 'Frontend/generated/theme';

const isMac = /Macintosh|MacIntel|MacPPC|Mac68K/.test(window.navigator.platform);

export class Example extends LitElement {
  protected createRenderRoot() {
    const root = super.createRenderRoot();
    // Apply custom theme (only supported if your app uses one)
    applyTheme(root);
    return root;
  }

  render() {
    return html`
      <vaadin-notification-card theme="contrast" slot="middle">
        <vaadin-horizontal-layout style="align-items: center;">
          <div>5 tasks deleted</div>
          <vaadin-button theme="primary" style="margin-left: var(--lumo-space-xl);">
            Undo ${isMac ? '⌘' : 'Ctrl-'}Z
          </vaadin-button>
        </vaadin-horizontal-layout>
      </vaadin-notification-card>
    `;
  }
}
Open in a
new tab
public Notification show() {
  Notification notification = new Notification();
  notification.setDuration(10000);
  notification.addThemeVariants(NotificationVariant.LUMO_CONTRAST);

  Div statusText = new Div(new Text("5 tasks deleted"));

  Button undoButton = new Button();
  undoButton.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
  undoButton.getElement().getStyle().set("margin-left", "var(--lumo-space-xl)");
  undoButton.getElement().executeJs(
    "const isMac = /Macintosh|MacIntel|MacPPC|Mac68K/.test(window.navigator.platform);" +
    "this.textContent = `Undo ${isMac ? '⌘' : 'Ctrl-'}Z`;"
  );
  undoButton.addClickListener(event -> {
    notification.close();
  });

  HorizontalLayout layout = new HorizontalLayout(statusText, undoButton);
  layout.setAlignItems(Alignment.CENTER);

  notification.add(layout);
  notification.open();

  return notification;
}

...

public void setupUndoShortcut(Notification notification) {
  Shortcuts.addShortcutListener(notification, notification::close, Key.of("z"), KeyModifier.META);
  Shortcuts.addShortcutListener(notification, notification::close, Key.of("z"), KeyModifier.CONTROL);
}

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.

Open in a
new tab
import { html, LitElement, customElement } from 'lit-element';
import '@vaadin/vaadin-avatar/vaadin-avatar';
import '@vaadin/vaadin-button/vaadin-button';
import '@vaadin/vaadin-icons/vaadin-icons';
import '@vaadin/vaadin-lumo-styles/icons';
import '@vaadin/vaadin-notification/vaadin-notification';
import '@vaadin/vaadin-ordered-layout/vaadin-horizontal-layout';
import { applyTheme } from 'Frontend/generated/theme';

@customElement('notification-rich-preview')
export class Example extends LitElement {
  protected createRenderRoot() {
    const root = super.createRenderRoot();
    // Apply custom theme (only supported if your app uses one)
    applyTheme(root);
    return root;
  }

  render() {
    return html`
      <vaadin-notification-card theme="success" slot="middle">
        <vaadin-horizontal-layout theme="spacing" style="align-items: center">
          <iron-icon icon="vaadin:check-circle"></iron-icon>
          <div>Application submitted!</div>
          <vaadin-button style="margin: 0 0 0 var(--lumo-space-l)">View</vaadin-button>
          <vaadin-button theme="tertiary-inline">
            <iron-icon icon="lumo:cross"></iron-icon>
          </vaadin-button>
        </vaadin-horizontal-layout>
      </vaadin-notification-card>

      <vaadin-notification-card theme="error" slot="middle">
        <vaadin-horizontal-layout theme="spacing" style="align-items: center">
          <iron-icon icon="vaadin:warning"></iron-icon>
          <div>Failed to generate report</div>
          <vaadin-button style="margin: 0 0 0 var(--lumo-space-l)">Retry</vaadin-button>
          <vaadin-button theme="tertiary-inline">
            <iron-icon icon="lumo:cross"></iron-icon>
          </vaadin-button>
        </vaadin-horizontal-layout>
      </vaadin-notification-card>

      <vaadin-notification-card slot="middle">
        <vaadin-horizontal-layout theme="spacing" style="align-items: center">
          <vaadin-avatar name="Jason Bailey"></vaadin-avatar>
          <div><b>Jason Bailey</b> mentioned you in <a href="#">Project Q4</a></div>
          <vaadin-button theme="tertiary-inline">
            <iron-icon icon="lumo:cross"></iron-icon>
          </vaadin-button>
        </vaadin-horizontal-layout>
      </vaadin-notification-card>

      <vaadin-notification-card slot="middle">
        <vaadin-horizontal-layout theme="spacing" style="align-items: center">
          <iron-icon
            icon="vaadin:check-circle"
            style="color: var(--lumo-success-color)"
          ></iron-icon>
          <div>
            <b style="color: var(--lumo-success-text-color);">Upload successful</b>
            <div
              style="font-size: var(--lumo-font-size-s); color: var(--lumo-secondary-text-color);"
            >
              <b>Financials.xlsx</b> is now available in <a href="#">Documents</a>
            </div>
          </div>
          <vaadin-button theme="tertiary-inline">
            <iron-icon icon="lumo:cross"></iron-icon>
          </vaadin-button>
        </vaadin-horizontal-layout>
      </vaadin-notification-card>
    `;
  }
}
Open in a
new tab
public static Notification createSubmitSuccess() {
    Notification notification = new Notification();
    notification.addThemeVariants(NotificationVariant.LUMO_SUCCESS);

    Icon icon = VaadinIcon.CHECK_CIRCLE.create();
    Div info = new Div(new Text("Application submitted!"));

    Button viewBtn = new Button(
            "View",
            clickEvent -> notification.close());
    viewBtn.getStyle().set("margin", "0 0 0 var(--lumo-space-l)");

    HorizontalLayout layout = new HorizontalLayout(
            icon, info, viewBtn,
            createCloseBtn(notification));
    layout.setAlignItems(Alignment.CENTER);

    notification.add(layout);

    return notification;
}

public static Notification createReportError() {
    Notification notification = new Notification();
    notification.addThemeVariants(NotificationVariant.LUMO_ERROR);

    Icon icon = VaadinIcon.WARNING.create();
    Div info = new Div(new Text("Failed to generate report!"));

    Button retryBtn = new Button(
            "Retry",
            clickEvent -> notification.close());
    retryBtn.getStyle().set("margin", "0 0 0 var(--lumo-space-l)");

    HorizontalLayout layout = new HorizontalLayout(
            icon, info, retryBtn,
            createCloseBtn(notification));
    layout.setAlignItems(Alignment.CENTER);

    notification.add(layout);

    return notification;
}

public static Notification createMentionNotification() {
    Notification notification = new Notification();

    Avatar avatar = new Avatar("Jason Bailey");

    Span name = new Span("Jason Bailey");
    name.getStyle().set("font-weight", "500");

    Div info = new Div(
            name,
            new Text(" mentioned you in "),
            new Anchor("#", "Project Q4")
    );

    HorizontalLayout layout = new HorizontalLayout(
            avatar, info,
            createCloseBtn(notification));
    layout.setAlignItems(Alignment.CENTER);

    notification.add(layout);

    return notification;
}

public static Notification createUploadSuccess() {
    Notification notification = new Notification();

    Icon icon = VaadinIcon.CHECK_CIRCLE.create();
    icon.setColor("var(--lumo-success-color)");

    Div uploadSuccessful = new Div(new Text("Upload successful"));
    uploadSuccessful
            .getStyle()
            .set("font-weight", "600")
            .set("color", "var(--lumo-success-text-color)");

    Span fileName = new Span("Financials.xlsx");
    fileName.getStyle()
            .set("font-size", "var(--lumo-font-size-s)")
            .set("font-weight", "600");

    Div info = new Div(uploadSuccessful, new Div(
            fileName,
            new Text(" is now available in "),
            new Anchor("#", "Documents")
    ));
    info.getStyle()
            .set("font-size", "var(--lumo-font-size-s)")
            .set("color", "var(--lumo-secondary-text-color)");

    HorizontalLayout layout = new HorizontalLayout(
            icon, info,
            createCloseBtn(notification));
    layout.setAlignItems(Alignment.CENTER);

    notification.add(layout);

    return notification;
}

public static Button createCloseBtn(Notification notification) {
    Button closeBtn = new Button(
            VaadinIcon.CLOSE_SMALL.create(),
            clickEvent -> notification.close());
    closeBtn.addThemeVariants(LUMO_TERTIARY_INLINE);

    return closeBtn;
}

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 may 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 immediate notifications.

Open in a
new tab
Span numberOfNotifications = new Span("4");
numberOfNotifications.getElement()
        .getThemeList()
        .addAll(Arrays.asList("badge", "error", "primary", "small", "pill"));
numberOfNotifications.getStyle()
        .set("position", "absolute")
        .set("transform", "translate(-40%, -85%)");

Button bellBtn = new Button(VaadinIcon.BELL_O.create());
bellBtn.addThemeVariants(ButtonVariant.LUMO_TERTIARY);
bellBtn.getElement().appendChild(numberOfNotifications.getElement());

Div sampleNotification = new Div(new Text("Show notifications here"));
sampleNotification.getStyle().set("padding", "var(--lumo-space-l)");

ContextMenu menu = new ContextMenu();
menu.setOpenOnClick(true);
menu.setTarget(bellBtn);
menu.add(sampleNotification);

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.

Open in a
new tab
Do show a preview of longer content, and link to the full details
import { html, LitElement } from 'lit-element';
import '@vaadin/vaadin-lumo-styles/icons';
import '@vaadin/vaadin-button/vaadin-button';
import '@vaadin/vaadin-notification/vaadin-notification';
import { applyTheme } from 'Frontend/generated/theme';

export class Example extends LitElement {
  protected createRenderRoot() {
    const root = super.createRenderRoot();
    // Apply custom theme (only supported if your app uses one)
    applyTheme(root);
    return root;
  }

  render() {
    return html`
      <vaadin-notification-card slot="middle">
        <div>
          <div>Aria Bailey</div>
          <div style="font-size: var(--lumo-font-size-s); color: var(--lumo-secondary-text-color);">
            Yeah, I know. But could you help me with...
          </div>
        </div>
        <vaadin-button>View</vaadin-button>
        <vaadin-button theme="tertiary-inline">
          <iron-icon icon="lumo:cross"></iron-icon>
        </vaadin-button>
      </vaadin-notification-card>
    `;
  }
}
Open in a
new tab
Don’t display all details in the notification
import { html, LitElement } from 'lit-element';
import '@vaadin/vaadin-lumo-styles/icons';
import '@vaadin/vaadin-button/vaadin-button';
import '@vaadin/vaadin-notification/vaadin-notification';
import { applyTheme } from 'Frontend/generated/theme';

export class Example extends LitElement {
  protected createRenderRoot() {
    const root = super.createRenderRoot();
    // Apply custom theme (only supported if your app uses one)
    applyTheme(root);
    return root;
  }

  render() {
    return html`
      <vaadin-notification-card slot="middle">
        <div>
          <div>New message from Aria Bailey</div>
          <div style="font-size: var(--lumo-font-size-s); color: var(--lumo-secondary-text-color);">
            Yeah, I know. But could you help me with this. I’m not sure where the bug is in my CSS?
            The checkmark doesn’t get the right color. I’m trying to use the CSS custom properties
            from our design system, but for some reason it’s not working.
          </div>
        </div>
        <vaadin-button theme="tertiary-inline">
          <iron-icon icon="lumo:cross"></iron-icon>
        </vaadin-button>
      </vaadin-notification-card>
    `;
  }
}
Component Usage recommendations

Dialog

Dialog should be used instead of Notification for anything that requires immediate user action.

52817CB4-44DD-49EF-B100-550906E6BABB