Notification

Create toggleable notifications that fade out automatically.

Notification

Create toggleable notifications that fade out automatically.

Usage

The notification will not fade out but remain visible when you hover the message until you stop hovering. You can also close the notification by clicking it. To show notifications, the component provides a simple JavaScript API. The following code snippet gets you started.

JavaScript

UIkit.notification({
    message: 'my-message!',
    status: 'primary',
    pos: 'top-right',
    timeout: 5000
});

// Shortcuts
UIkit.notification('My message');
UIkit.notification('My message', status);
UIkit.notification('My message', { /* options */ });

HTML message

You can use HTML inside your notification message, like an icon from the Icon component.

UIkit.notification("<span uk-icon='icon: check'></span> Message");

Position

Add one of the following parameters to adjust the notification’s position to different corners.

UIkit.notification("", {pos: 'top-right'})
PositionCode
top-leftUIkit.notification("…", {pos: 'top-left'})
top-centerUIkit.notification("…", {pos: 'top-center'})
top-rightUIkit.notification("…", {pos: 'top-right'})
bottom-leftUIkit.notification("…", {pos: 'bottom-left'})
bottom-centerUIkit.notification("…", {pos: 'bottom-center'})
bottom-rightUIkit.notification("…", {pos: 'bottom-right'})

Style

A notification can be styled by adding a status to the message to indicate a primary, success, warning or a danger status.

UIkit.notification("", {status: 'primary'})
StyleCode
primaryUIkit.notification("…", {status:'primary'})
successUIkit.notification("…", {status:'success'})
warningUIkit.notification("…", {status:'warning'})
dangerUIkit.notification("…", {status:'danger'})

Close all

You can close all open notifications by calling UIkit.notification.closeAll().


Component options

Any of these options can be applied to the component attribute. Separate multiple options with a semicolon. Learn more

OptionValueDefaultDescription
message StringfalseNotification message to show.
statusStringnullNotification status color.
timeoutNumber5000Visibility duration until a notification disappears. If set to 0, notification will not hide automatically.
groupStringnullUseful, if you want to close all notifications in a specific group.
posStringtop-centerDisplay corner.

JavaScript

Learn more about JavaScript components.

Initialization

This is a Functional Component and may omit the element argument.

UIkit.notification(options);
UIkit.notification(message, status);

Events

The following events will be triggered on elements with this component attached:

NameDescription
closeFires after the notification has been closed.

Methods

The following methods are available for the component:

Close

UIkit.notification(element).close(immediate);

Closes the notification.

NameTypeDefaultDescription
immediateBooleantrueTransition the notification out.