Add your own "Install app" button with beforeinstallprompt

Offer installation at the right moment, in your own words.

Installation Beginner 2 min read Reviewed Nov 27, 2026

Chromium browsers (Chrome, Edge, Samsung Internet, Opera) fire a beforeinstallprompt event when your site meets the install criteria. You can catch it, keep it, and show the install dialog from your own button at a better moment.

The code

let deferredPrompt = null;
const btn = document.querySelector('#install');

window.addEventListener('beforeinstallprompt', (event) => {
  event.preventDefault();          // stop the mini-infobar on Android
  deferredPrompt = event;          // keep it for later
  btn.hidden = false;              // now it makes sense to show the button
});

btn.addEventListener('click', async () => {
  if (!deferredPrompt) return;
  deferredPrompt.prompt();         // must be called from a user gesture
  const { outcome } = await deferredPrompt.userChoice; // 'accepted' or 'dismissed'
  analytics('install_prompt', { outcome });
  deferredPrompt = null;           // each event can be used only once
  btn.hidden = true;
});

window.addEventListener('appinstalled', () => {
  btn.hidden = true;
  analytics('app_installed');
});

prompt() can only be called once per event. If the user dismisses it, Chrome fires the event again later (after a cool-down), so keep listening.

When to show it

The best install prompts appear after the user has seen value:

  • after they finish a task (a booking, a saved note, a completed lesson);
  • on their second or third visit;
  • next to a feature that works better installed (offline reading, notifications).

Avoid showing a full-screen install banner on the first page view. It annoys people, and it has the opposite effect.

iPhone and iPad

beforeinstallprompt does not exist in Safari. Detect iOS and, if the app is not already running standalone, show short instructions instead:

const isIOS = /iphone|ipad|ipod/i.test(navigator.userAgent) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1);
const standalone = matchMedia('(display-mode: standalone)').matches || navigator.standalone;
if (isIOS && !standalone) showHint('Tap the Share button, then "Add to Home Screen".');

See install on iPhone and iPad for wording and screenshots.

Hide the button when installed

@media (display-mode: standalone) { #install { display: none; } }

Ready-made components

  • pwa-install by Gleb Khmyznikov: a web component with polished install dialogs for Chromium, with gallery screenshots, and step-by-step guides for iOS, iPadOS and macOS Safari.
  • Our install button generator writes the code above, with your own text and an iOS hint.

PWA.live uses this exact pattern: the install icon in the header appears only when your browser can install the site.

Browser support

Browser support for Progressive Web App features
FeatureChrome / Edge desktopChrome AndroidSafari iOS / iPadOSSafari macOSFirefox desktopFirefox AndroidSamsung Internet
beforeinstallprompt (own install button) Chrome / Edge desktop: Yes Chrome Android: Yes Safari iOS / iPadOS: No Safari macOS: No Firefox desktop: No Firefox Android: No Samsung Internet: Yes
Install from the browser Chrome / Edge desktop: Yes (Address bar icon and menu) Chrome Android: Yes (Installs a WebAPK) Safari iOS / iPadOS: Yes (Share > Add to Home Screen (manual)) Safari macOS: Yes (File > Add to Dock (Safari 17+)) Firefox desktop: Partial (Windows only, Firefox 143+) Firefox Android: Yes (Add to Home screen) Samsung Internet: Yes

See the full support table