HTML5 Desktop Notifications

Posted on: June 4, 2016 by Dimitar Ivanov

Web notifications

Thanks to HTML5 specification modern browsers are able to display desktop notifications. If you ever have seen such a popup, that is because user-agent asks for permission to display web notifications from current domain.

Web notification request permission
Figure 1. Web notification request permission

Granting permission the domain for notifications, allows the website to display notifications, that looks like this:

Web notification
Figure 2. Web notification

The icon at the bottom right corner of the notification, allows you to manage the notification exceptions.

Notifications exceptions
Figure 3. Notifications exceptions

In Chrome, navigate to Settings » Privacy » Content settings... » Notifications » Manage exceptions...

Notification API

  • How to check whether notifications are supported:
    if ('Notification' in window) {
  • To find out the current permission to display notifications, use the permission static property. Possible values are: granted, denied and default.
    if (Notification.permission !== 'denied') {
  • How to ask for permission:
    Notification.requestPermission(function (permission) {
        if (permission === 'granted') {
            // create notification
  • How to create notification:
    var note = new Notification('Hooray!', {
        icon: '',
        body: 'Lorem ipsum dolor sit amet.'
  • The notification object supports onclick and onerror event handlers.
    note.onclick = function(e) {
        e.preventDefault();'', '_blank');
  • How to close notification:

Browser Compatibility

Edge 14+, Firefox 22+, Chrome 22+, Safari 6+, Opera 25+


Web notifications are great addition to the web platform and could be used practically anywhere. That makes them extremely useful.

See also
Share this post

If you have any questions or toughts about the HTML5 Desktop Notifications, leave a comment below. Ah, don't forget to share this article.


Comments are closed