# Install prompt UX

> How to reveal a PWA install button after beforeinstallprompt, handle its one-use event, detect installed display mode, and provide a fallback.

An install prompt lets users install a PWA from a page. You can choose when to show a custom install button and what help to offer when no programmatic prompt is available. The custom button depends on the limited-availability `beforeinstallprompt` event, while the fallback leaves installation to browser-provided UI.

## How it works

The site's install button starts hidden. When `beforeinstallprompt` fires, the handler can call `preventDefault()`, retain the event, and reveal the button. A later click calls the retained event's `prompt()` method. web.dev states that a retained event can be used only once, so the page clears it after prompting ([How to provide your own in-app install experience](https://web.dev/articles/customize-install), web.dev).

Firefox and Safari do not support `BeforeInstallPromptEvent`, according to browser-compat-data. Keep a browser-provided installation path available when using the event to enhance your install flow.

The `display-mode` media feature reports the display mode being used. MDN documents values including `browser`, `standalone`, `minimal-ui`, `fullscreen`, and `window-controls-overlay`. A match for one value describes the active display mode; it does not by itself prove every possible installed state.

:::caution
MDN says calling `preventDefault()` on `beforeinstallprompt` prevents browser-provided install UI from appearing on some platforms. Do not cancel the event unless the page supplies a reachable custom action that can call `prompt()`.
:::

## Examples

Keep the install action tied to the retained event. Check display mode separately; it cannot establish installation in all cases.

### Revealing a button only after the event

Keep the browser's own UI available when the event is absent, and clear the retained event after use.

```html
<button id="install" type="button" hidden>Install app</button>

<script>
const installButton = document.querySelector('#install');
let deferredInstall;

window.addEventListener('beforeinstallprompt', (event) => {
  event.preventDefault();
  deferredInstall = event;
  installButton.hidden = false;
});

installButton.addEventListener('click', async () => {
  if (!deferredInstall) return;
  await deferredInstall.prompt();
  deferredInstall = undefined;
  installButton.hidden = true;
});

window.addEventListener('appinstalled', () => {
  deferredInstall = undefined;
  installButton.hidden = true;
});
</script>
```

If no `beforeinstallprompt` event arrives, the button remains hidden.

### Selecting an in-app message or a manual fallback

Feature detection decides whether to wait for the event. For the fallback, render browser-specific help from maintained instructions. Avoid guessing menu labels in JavaScript.

```js
const standalone = window.matchMedia('(display-mode: standalone)').matches;
const canReceivePrompt = 'onbeforeinstallprompt' in window;

if (standalone) {
  hideInstallPromotion();
} else if (canReceivePrompt) {
  keepInstallButtonHiddenUntilEvent();
} else {
  showManualInstallHelp();
}
```

Handle an absent event explicitly. If your app supports additional installed display modes, test those modes separately.

## Observed behaviour

:::note
WebKit's [Safari 26.0 release post](https://webkit.org/blog/17333/webkit-features-in-safari-26-0/) names the English labels **Add to Home Screen** and **Open as Web App** for adding a site from Safari on iOS 26 and iPadOS 26. This is browser-provided UI. The MDN browser compatibility data lists `beforeinstallprompt` as unsupported in Safari on iOS, so the page receives no event for it.
:::

The manual fallback can point to those documented labels when its maintained instructions identify Safari 26 on iOS or iPadOS.

## See also

- [How to provide your own in-app install experience](https://web.dev/articles/customize-install) (web.dev)
- [Window: beforeinstallprompt event](https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeinstallprompt_event) (developer.mozilla.org)
- [beforeinstallprompt event](/reference/installation/install-prompt/)
- [Installability criteria](/reference/installation/installability-criteria/)
- [iOS Add to Home Screen](/reference/installation/ios-add-to-home-screen/)
- [Desktop installation](/reference/installation/desktop-install/)