Web · Components
InstallPrompt
"Install the app" card that appears once the app is installable.
Live example
Preview
- canInstall
- no
- promptReady
- no
- guide
- null
- installed
- no
Code
Events
- Events appear here when you interact with the preview.
Manual install steps (InstallGuide): iOS, macOS Safari, Android, desktop
Preview
- supported
- no
- registration
- null
- updateAvailable
- no
- offlineReady
- no
- error
- null
Code
Events
- Events appear here when you interact with the preview.
Preview
- online
- evet
- effectiveType
- unknown
- saveData
- no
- downlink
- unknown
- rtt
- unknown
Code
Events
- Events appear here when you interact with the preview.
Preview
The striped area is the safe area: `env(safe-area-inset-*)` on a phone with a notch, here 1rem.
Code
Events
- Events appear here when you interact with the preview.
Preview
- useDisplayMode()
- browser
- useIsStandalone()
- no
- useOnlineStatus()
- evet
- useWakeLock()
- supported: false, locked: false
- useAppBadge()
- no badge
Tailwind standalone: prefix, right now: standalone:inlinenot-standalone
Code
Events
- Events appear here when you interact with the preview.
Import
"Install the app" card that appears once the app is installable.
- In browsers like Chrome, Edge, Samsung Internet, "Install" opens the browser's install window with one tap.
- In iOS and macOS Safari, the "How to install?" button shows the steps (
InstallGuide). - Never shows if the app was opened installed or once it is installed.
- After "Not now" it doesn't come back for
dismissDaysdays.
Putting it once in the root layout is enough. For the browser to offer install, the site must have a web app manifest (Next.js: app/manifest.ts). Renders nothing on the server and on first hydration.
Examples
Window showing the steps to add the app to the home screen in environments without the browser's own install prompt (iOS, macOS Safari). Opens from the bottom on mobile. InstallPrompt and InstallButton open it themselves; pass trigger to open it with your own button.
Texts can be changed in the dictionary's ui namespace (installIosShare, installIosAdd…; see UIProvider messages).
Examples
"Install the app" button: in a menu, header or settings. If install is not possible (installed, unsupported) it is not rendered at all; in iOS and macOS Safari it opens the steps (InstallGuide). Takes all appearance props of Button.
Examples
"You're offline" indicator that appears at the screen edge when the connection drops; when it returns it briefly says "You're back online" and disappears. Also announced to screen readers. Renders nothing while online.
Put it once in the root layout. For your own UI, useOnlineStatus.
Examples
Box that insets content so it doesn't sit under the notch, camera island, rounded corners and home bar. Used for the top header and bottom navigation bar in full screen (PWA) apps.
Edge insets exist only if the page covers the whole screen; in Next.js enable it with export const viewport = { viewportFit: "cover" }. If you only need classes, there are also the pt-safe, pb-safe, px-safe… utilities.
It is a server component; it contains no client code.
Examples
Binds the <meta name="theme-color"> value to the page theme: the browser's address bar and the installed app's title and status bar change color with the theme (light, dark, custom themes). Renders nothing.
Put it once in the root layout, inside or next to ThemeProvider. It detects theme changes from the class, data-theme and style changes on <html> and from the system light/dark preference.
Note: it replaces the fixed value given with Next.js viewport.themeColor; don't use both.
Examples
Registers the service worker and shows a "New version ready — Reload" card when a new version is downloaded. When the user reloads, the waiting version is activated and the page reloads once; if closed with ×, the version activates by itself on the next launch.
Put it once in the root layout. Your service worker file must listen for the SKIP_WAITING message; for details and your own UI see useServiceWorker. If a tool like Serwist or Workbox does the registration itself, pass register={false}.
Examples
getInstallGuide
functionDetects an environment where the browser doesn't support its own install window (beforeinstallprompt) but allows manual install: all browsers on iOS/iPadOS and macOS Safari. Returns null elsewhere; there install is one tap with useInstallPrompt. Returns null on the server.
Can be called in server components too (it isn't client code); but the result is only meaningful in the browser.
Examples
setAppBadge
functionSets the badge on the installed app's icon (home screen, Dock, taskbar). If no number is given or it is true, a dot without a number is shown; 0 or false removes the badge. Silently does nothing in unsupported browsers (and in most browsers while open in a tab).
iOS/iPadOS 16.4+ shows it only for apps added to the home screen with notification permission granted.
Examples
useAppBadge
functionBinds the app icon badge to a value: the badge updates as the value changes and is cleared when the component unmounts. Suitable for unread message or pending task counts. See setAppBadge.
Examples
useDisplayMode
functionTracks which window mode the app was opened in: browser tab ("browser") or installed app ("standalone", "fullscreen"…). The value updates when the user moves the app from a tab to a window.
Returns "browser" on the server and on first hydration. To change only the look, prefer Tailwind's standalone: prefix (standalone:hidden); this hook is needed when behavior changes.
Examples
useIsStandalone
functionReturns true if the app was opened as installed (from the home screen, Dock, in an app window). Returns false on the server and on first hydration.
Examples
useInstallPrompt
functionTracks whether the app is installable and opens the install window. Use it if you build your own button or card; the ready-made ones are InstallPrompt and InstallButton.
For the browser to offer an install window, the site needs a valid web app manifest (app/manifest.ts in Next.js), HTTPS and icons of at least 192 and 512 px. iOS and macOS Safari don't offer a window; there the steps are shown with guide.
If the user rejects the browser's window, Chrome won't offer it again for a while (about three months); so show the prompt at the right moment.
Examples
useOnlineStatus
functionTracks whether the device is connected to a network. Returns true on the server and on first hydration. OfflineIndicator is ready-made for showing it to the user.
Note: true isn't definite proof of internet access (e.g. a captive Wi-Fi); false means the connection is definitely missing.
Examples
useNetworkStatus
functionTracks the connection status in detail: online or not, estimated speed, data saver. Used to serve lighter content on slow connections. If you only need online/offline, useOnlineStatus re-renders less.
Examples
useServiceWorker
functionRegisters the service worker and tracks new versions. The ready-made component for telling the user "New version ready" is UpdatePrompt; use this hook if you build your own UI. Can be called in several places; registration happens once and the state is shared.
When a new version is installed, the browser keeps it waiting (open tabs keep running the old version). update() sends the SKIP_WAITING message to the waiting worker; when the worker activates the page reloads once. For this your service worker file needs this listener:
A new version is checked when the page opens, when returning to the tab and every updateInterval (while online).
Examples
useWakeLock
functionWhile active is true, prevents the device screen from dimming and locking: for recipe, directions, presentation, payment QR code screens. When the tab goes to the background the browser releases the lock; on returning to the tab the hook reacquires it by itself. Released on unmount.
Silently does nothing in unsupported browsers or battery saver mode; locked stays false.
Examples
InstallGuideProps
interfaceProps of the InstallGuide component.
| Name | Type | Default | Description |
|---|---|---|---|
guide? | InstallGuideKind | Steps to show. If omitted, picked by environment (iOS, macOS Safari); "desktop" if none is found. | |
open? | boolean | Whether it is open (controlled). | |
onOpenChange? | (open: boolean) => void | Called when open/close changes. | |
trigger? | ReactElement | Element that opens the window when clicked (uncontrolled use). | |
title? | ReactNode | messages.installGuideTitle | Title. |
description? | ReactNode | messages.installGuideDescription | Description. |
image? | string | ReactNode | Icon of the window: the app icon (image URL or element). |
InstallPromptProps
interfaceProps of the InstallPrompt component.
| Name | Type | Default | Description |
|---|---|---|---|
title? | ReactNode | messages.installTitle | Title. |
description? | ReactNode | messages.installDescription | Description. |
image? | string | ReactNode | App icon at the left of the card: image URL ("/icon-192.png"), icon name or element. If omitted, a download icon. | |
icon? | IconProp | Icon from the library instead of image. | |
installLabel? | ReactNode | messages.install | Text of the install button. |
dismissLabel? | ReactNode | messages.notNow | Text of the dismiss button; hidden with null. |
position? | PromptPosition | "bottom-center" | Position of the card. See PromptPosition. |
enabled? | boolean | true | Not shown while false. Use it to show the prompt at the right moment: e.g. when the user comes back a second time or finishes a task. |
delay? | number | 0 | How many ms to wait after it becomes installable before showing. |
dismissDays? | number | 14 | For how many days it is not shown after closing with "Not now" or ×. With 0 it is hidden only while this page is open. |
storageKey? | string | false | "ui-install-prompt" | localStorage key where the dismiss period is stored. Pass a different key if the site has several prompts; false stores nothing. |
guide? | boolean | true | In manually installed environments (iOS, macOS Safari) shows the steps with a "How to install?" button. With false no prompt appears there. |
onInstall? | (outcome: InstallOutcome) => void | Called when the user makes a choice in the browser's window. | |
onDismiss? | () => void | Called when the user closes or dismisses the prompt. | |
className? | string | Classes added to the card element. | |
classNames? | PromptClassNames | Classes added to the inner parts. |
InstallButtonProps
interfaceProps of the InstallButton component.
Extends: Omit<ButtonAsButtonProps, "onClick" | "href">
| Name | Type | Default | Description |
|---|---|---|---|
fallback? | ReactNode | What to render when install is not possible. If omitted, nothing is rendered, so the button only appears when it is useful. | |
guide? | boolean | true | In manually installed environments (iOS, macOS Safari) shows the steps. With false the button isn't rendered there. |
onInstall? | (outcome: InstallOutcome) => void | Called when the user makes a choice in the browser's window. |
Style of the indicator.
pill: small pill floating at the center of the screen.bar: thin strip along the screen edge.
OfflineIndicatorProps
interfaceProps of the OfflineIndicator component.
| Name | Type | Default | Description |
|---|---|---|---|
variant? | OfflineIndicatorVariant | "pill" | Style. |
side? | "top" | "bottom" | "top" | Which edge of the screen. |
offlineLabel? | ReactNode | messages.offline | Text while offline. |
onlineLabel? | ReactNode | messages.backOnline | Text shown briefly when the connection returns; not shown with null. |
onlineDuration? | number | 3000 | How long (ms) the "back online" text stays on screen. |
onChange? | (online: boolean) => void | Called when the connection status changes. | |
className? | string | Classes added to the indicator. |
InstallGuideKind
typeKind of manual install steps: the path shown to the user when the browser has no install window of its own.
ios: iPhone/iPad; Share → Add to Home Screen.macos: macOS Safari; File → Add to Dock.android: Android browser menu (⋮) → Install app.desktop: install icon in the Chrome/Edge address bar.
DisplayMode
typeWindow mode the app was opened in; depends on the manifest's display value and how the user opened the app. browser is a normal browser tab; the others are an installed app.
PromptPosition
typePosition of the prompt card. inline is rendered in the page flow where it is placed; the others are fixed to the screen. On mobile (below 640 px) fixed cards are always full width and respect the notch/home bar inset.
PromptClassNames
interfaceClasses that can be passed to the inner parts of the InstallPrompt and UpdatePrompt card.
| Name | Type | Description |
|---|---|---|
icon? | string | Icon box. |
title? | string | Title. |
description? | string | Description. |
actions? | string | Button area. |
SafeAreaEdge
typeEdge of the screen.
SafeAreaProps
interfaceProps of the SafeArea component.
Extends: ComponentProps<"div">
| Name | Type | Default | Description |
|---|---|---|---|
edges? | readonly SafeAreaEdge[] | ["top", "right", "bottom", "left"] | Edges to pad. |
min? | string | "0px" | Minimum padding kept even on devices without a notch (CSS length), e.g. "1rem". If the edge inset is larger, that is used. |
as? | "div" | "header" | "footer" | "main" | "nav" | "section" | "aside" | "div" | Element to render. |
ThemeColorProps
interfaceProps of the ThemeColor component.
| Name | Type | Default | Description |
|---|---|---|---|
color? | string | "var(--ui-background)" | Color for the status bar: any CSS color or variable. |
UpdatePromptProps
interfaceProps of the UpdatePrompt component.
| Name | Type | Default | Description |
|---|---|---|---|
title? | ReactNode | messages.updateTitle | Title. |
description? | ReactNode | messages.updateDescription | Description; hidden with null. |
icon? | IconProp | refresh icon | Icon of the card: name or element. |
reloadLabel? | ReactNode | messages.reload | Text of the reload button. |
position? | PromptPosition | "bottom-center" | Position of the card. See PromptPosition. |
offlineReady? | boolean | ReactNode | false | Whether to show a "ready for offline use" notification (toast) when the service worker is installed for the first time. If text is given, it is used. |
onUpdate? | () => void | Called when the user chooses to reload, right before the page reloads. | |
className? | string | Classes added to the card element. | |
classNames? | PromptClassNames | Classes added to the inner parts. | |
url? | string | "/sw.js" | URL of the service worker file. In Next.js public/sw.js → "/sw.js". |
scope? | string | Path the service worker controls. If omitted, the folder of the file. | |
type? | WorkerType | "classic" | "module" if the file is an ES module. |
register? | boolean | true | When false the hook doesn't register the file itself; it tracks the service worker registered by another tool (Serwist, Workbox…). |
enabled? | boolean | true | Does nothing when false. Usually enabled={process.env.NODE_ENV === "production"} is passed so caching doesn't confuse you during development. |
updateInterval? | number | 3600000` (1 hour) | How often (ms) to check for a new version while the page stays open. With 0 it is checked only when the page opens and when returning to the tab. |
InstallOutcome
typeResult of the install request.
InstallPromptState
interfaceValue returned by the useInstallPrompt hook.
| Name | Type | Description |
|---|---|---|
canInstall | boolean | Whether install can be offered to the user. true if one-tap install is ready or manual install steps (guide) exist and the app is not yet installed. false on the server and on first hydration. |
promptReady | boolean | Whether the browser's own install window is ready (Chrome, Edge, Samsung Internet…). |
guide | InstallGuideKind | null | Kind of steps in an environment without one-tap install but with manual install (iOS, macOS Safari); null otherwise. InstallGuide shows the steps. |
installed | boolean | The app was opened installed or was installed in this session. |
install | () => Promise<InstallOutcome> | Opens the browser's install window and returns the user's choice. If the window isn't ready it returns "unavailable"; then show the steps if guide exists. Can only be called inside a click. |
ConnectionType
typeEstimated speed of the connection (Network Information API).
NetworkStatus
interfaceValue returned by the useNetworkStatus hook.
| Name | Type | Description |
|---|---|---|
online | boolean | Whether the device is connected to a network. true on the server. |
effectiveType | ConnectionType | undefined | Estimated speed of the connection. Only Chromium-based browsers report it; undefined in others. |
saveData | boolean | Whether the user asked for "data saver". Defer heavy content (video, large images). |
downlink | number | undefined | Estimated download speed (Mbps). undefined if unknown. |
rtt | number | undefined | Estimated round-trip time (ms). undefined if unknown. |
UseServiceWorkerOptions
interfaceOptions of the useServiceWorker hook.
| Name | Type | Default | Description |
|---|---|---|---|
url? | string | "/sw.js" | URL of the service worker file. In Next.js public/sw.js → "/sw.js". |
scope? | string | Path the service worker controls. If omitted, the folder of the file. | |
type? | WorkerType | "classic" | "module" if the file is an ES module. |
register? | boolean | true | When false the hook doesn't register the file itself; it tracks the service worker registered by another tool (Serwist, Workbox…). |
enabled? | boolean | true | Does nothing when false. Usually enabled={process.env.NODE_ENV === "production"} is passed so caching doesn't confuse you during development. |
updateInterval? | number | 3600000` (1 hour) | How often (ms) to check for a new version while the page stays open. With 0 it is checked only when the page opens and when returning to the tab. |
ServiceWorkerState
interfaceValue returned by the useServiceWorker hook.
| Name | Type | Description |
|---|---|---|
supported | boolean | Whether the browser supports service workers. false on the server. |
registration | ServiceWorkerRegistration | null | The registration; null if not registered yet. |
updateAvailable | boolean | A new version is downloaded and waiting to activate. |
offlineReady | boolean | The service worker was installed for the first time; the app now opens offline too. |
error | unknown | The error, if registration failed. |
update | () => void | Activates the waiting new version and reloads the page. The service worker must listen for the { type: "SKIP_WAITING" } message (see the hook description). |
checkForUpdate | () => Promise<void> | Checks for a new version right away. |
WakeLockState
interfaceValue returned by the useWakeLock hook.
| Name | Type | Description |
|---|---|---|
supported | boolean | Whether the browser supports keeping the screen on. false on the server. |
locked | boolean | Whether the screen is currently kept on. |