This feature is not Baseline because it does not work in some of the most widely-used browsers.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Note: This feature is available in Web Workers.
The Notification() constructor creates a new Notification object instance, which represents a user notification.
Note: Trying to create a notification inside the ServiceWorkerGlobalScope using the Notification() constructor will throw a TypeError. Use ServiceWorkerRegistration.showNotification() instead.
new Notification(title) new Notification(title, options)
titleDefines a title for the notification, which is shown at the top of the notification window.
options OptionalAn options object containing any custom settings that you want to apply to the notification. The possible options are:
actions OptionalMust be unspecified or an empty array. actions is only supported for persistent notifications fired from a service worker using ServiceWorkerRegistration.showNotification().
badge OptionalA string containing the URL of the image used to represent the notification when there isn't enough space to display the notification itself; for example, the Android Notification Bar. On Android devices, the badge should accommodate devices up to 4x resolution, about 96x96px, and the image will be automatically masked.
body OptionalA string representing the body text of the notification, which is displayed below the title. The default is the empty string.
data OptionalArbitrary data that you want associated with the notification. This can be of any structured-clonable data type. The default is null.
dir OptionalThe direction in which to display the notification. It defaults to auto, which just adopts the browser's language setting behavior, but you can override that behavior by setting values of ltr and rtl (although most browsers seem to ignore these settings.)
icon OptionalA string containing the URL of an icon to be displayed in the notification.
image OptionalA string containing the URL of an image to be displayed in the notification.
lang OptionalThe notification's language, as specified using a string representing a language tag according to RFC 5646: Tags for Identifying Languages (also known as BCP 47). See the Sitepoint ISO 2 letter language codes page for a simple reference. The default is the empty string.
renotify OptionalA boolean value specifying whether the user should be notified after a new notification replaces an old one. The default is false, which means they won't be notified. If true, then tag also must be set.
requireInteraction OptionalIndicates that a notification should remain active until the user clicks or dismisses it, rather than closing automatically. The default value is false.
silent OptionalA boolean value specifying whether the notification should be silent, i.e., no sounds or vibrations should be issued regardless of the device settings. If set to true, the notification is silent; if set to null (the default value), the device's default settings are respected.
tag OptionalA string representing an identifying tag for the notification. The default is the empty string.
timestamp OptionalA timestamp, given as Unix time in milliseconds, representing the time associated with the notification. This could be in the past when a notification is used for a message that couldn't immediately be delivered because the device was offline, or in the future for a meeting that is about to start.
vibrate OptionalA vibration pattern for the device's vibration hardware to emit with the notification. If specified, silent must not be true.
An instance of the Notification object.
TypeErrorThrown if:
ServiceWorkerGlobalScope.actions option is specified and is not empty.silent option is true and the vibrate option is specified.renotify option is true but the tag option is empty.DataCloneError DOMException
Thrown if serializing the data option failed for some reason.
Here is a most basic example to only show a notification if permission is already granted. For more complete examples, see the Notification page.
if (Notification.permission === "granted") {
const notification = new Notification("Hi there!");
}
| Specification |
|---|
| Notifications API> # dom-notification-notification> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
Notification |
20 | 14 | 224 | 23 | 7 | 42["A notification can only be sent from a service worker. To show a notification, seeServiceWorkerRegistration.showNotification().", "This constructor always throws a TypeError exception."] |
224 | 29["A notification can only be sent from a service worker. To show a notification, seeServiceWorkerRegistration.showNotification().", "This constructor always throws a TypeError exception."] |
16.4["This constructor throws aReferenceError exception, unless the page is a web app saved to the home screen. The app's manifest must have a non-default display value.", "A notification can only be sent from a service worker. To show a notification, see ServiceWorkerRegistration.showNotification()."] |
4.0["A notification can only be sent from a service worker. To show a notification, seeServiceWorkerRegistration.showNotification().", "This constructor always throws a TypeError exception."] |
No | No |
Starting in Chrome 49, notifications don't work in incognito mode.
Chrome for Android will throw a TypeError when calling the Notification constructor. It only supports creating notifications from a service worker. See the Chromium issue tracker for more details.
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Notification/Notification