The Notifications API is a browser interface that lets a web page or web application display system-level notifications outside the browser viewport, in the notification area of the operating system. Among Web APIs, it is the presentation layer for alerts: it controls how a message looks and how the user can interact with it, while other APIs decide when that message arrives.
Using the interface always requires explicit permission from the user, granted per origin. Notifications can be created from a visible page with the Notification constructor or from a service worker with showNotification(), and the second route is what allows messages to appear when no tab is open, in combination with web push.
How the Notifications API works
The flow has three stages: permission, creation and interaction. The page first checks Notification.permission, which is default, granted or denied. If the value is default, the page calls Notification.requestPermission(), and modern browsers accept that call only in response to a user gesture such as a click.
Once permission is granted, a script creates a notification with a title and an options object. The browser hands it to the operating system, which renders it in its own style, so the exact appearance differs between Windows, macOS, Android and Linux desktops.
| Option | Purpose | Practical note |
|---|---|---|
| body | Main message text | Keep it short; systems truncate long text |
| icon | Image identifying the sender | Square image, often 192 px |
| tag | Groups or replaces related notifications | Same tag replaces the older message |
| requireInteraction | Keeps the notification until acted on | Ignored on some platforms |
| actions | Up to a small number of buttons | Service worker notifications only |
| silent | Suppresses sound and vibration | Useful for low-priority updates |
| data | Arbitrary payload for click handling | Stores a target address or identifier |
Page notifications versus service worker notifications
The API offers two ways to show a notification, and the difference determines what an application can do. A page-level notification lives only as long as the page; a service worker notification is owned by the browser and survives closed tabs.
| Aspect | Notification constructor | ServiceWorkerRegistration.showNotification |
|---|---|---|
| Requires an open page | Yes | No |
| Action buttons | Not supported | Supported |
| Click handling | onclick on the object | notificationclick event in the worker |
| Mobile support | Limited, often unavailable | Standard route on Android |
| Typical use | Alerts while the app is open | Push messages and background events |
Because mobile browsers increasingly disallow the constructor, robust applications register a service worker and use showNotification() for every notification, even when the page is visible.
Relationship to web push and other APIs
The Notifications API is often confused with web push, but the two solve different problems. The Push API delivers a message from a server to a service worker; the Notifications API shows something to the user. A push message must normally lead to a visible notification, because browsers penalize or block silent pushes.
| Interface | What it does | Relation to notifications |
|---|---|---|
| Push API | Receives server messages in a service worker | Usually triggers showNotification |
| Server-sent events | Streams updates to an open page | Can trigger page-level notifications |
| WebSocket | Two-way real-time channel | Same, but only while connected |
| Badging API | Sets a count on the app icon | Quieter alternative to a notification |
| Permissions API | Queries permission state | Reads notification permission without prompting |
Permission strategy and user experience
Permission requests are one-shot and hard to undo. When a user selects block, the page cannot ask again, and only the user can reverse the choice in browser settings. Browsers also apply quieter permission prompts to sites whose requests are widely rejected.
- Ask in context: request permission after a user action that clearly benefits from alerts, such as following an order.
- Explain first: show an in-page message describing what will be sent before triggering the browser prompt.
- Offer control: provide in-app settings to choose notification types and frequency.
- Respect focus: avoid notifying about events the user is already looking at on screen.
A prompt on the first page view without context is the most common reason for low acceptance. A delayed, explained prompt tends to produce fewer but more meaningful subscriptions.
Frequency matters as much as the initial request. Users who receive too many low-value alerts tend to revoke permission at the browser level, which removes the channel for every future message. A practical rule is to send notifications only for events that are personal, timely and actionable, such as a delivery status, a reply to the user or a security warning, and to group minor updates into a single summary message.
Constraints and common mistakes
Support varies across platforms. On iOS and iPadOS, web notifications work only for web apps added to the home screen, and focus modes or system settings can silence them entirely. The API also requires a secure context, meaning HTTPS or localhost.
| Problem | Cause | Fix |
|---|---|---|
| Prompt never appears | Request not tied to a user gesture | Call requestPermission inside a click handler |
| Constructor throws on Android | Page-level notifications unsupported | Use a service worker |
| Duplicate alerts | Same event shown by several tabs | Use a shared tag |
| Click opens a blank tab | No target stored with the notification | Put the address in the data option |
| Nothing shown on iPhone | Site not installed as a web app | Guide users to add it to the home screen |
In plain words
When a chat app on your phone shows a message on your lock screen, that is a notification. The Notifications API lets websites do the same thing, so a web app can tap you on the shoulder even when you are looking at another window.
A website can only do this after you say yes. If you refuse, it cannot keep asking, and you can switch notifications off again in your browser settings at any time.
A real-world example
A regional food delivery service runs its ordering platform as a web application. Customers previously kept the order page open and refreshed it to see whether the courier had left the restaurant.
The developers add a service worker and, after the customer places an order, show a short in-page message offering status updates, followed by the browser permission prompt. Courier events are sent through web push, and the service worker displays each one with showNotification(), using one shared tag per order so that each new status replaces the previous one.
Customers can now close the tab and still see pickup and arrival alerts in their system notification area. Because the prompt appears only at a meaningful moment, far fewer users block notifications than with the earlier prompt on the home page.