Document PiP: Build Useful Always-On-Top Web UI


TL;DR: Document Picture-in-Picture (Document PiP) gives a web app a small, always-on-top document window rather than a floating video element. It is a strong fit for video calls, media controls, timers, dashboards, and note-taking companions—but it should be treated as an optional enhancement because browser support is still uneven. The practical architecture is to keep state in the main app, render a deliberately small companion UI into the PiP window, copy only the styles it needs, and restore cleanly when the window closes.

The web has spent years choosing between a single, crowded browser tab and a separate popup with all the usual popup problems. Document PiP creates a useful middle ground: a same-origin, browser-managed window that stays above other windows while its opener remains alive. It is especially interesting now because product teams are building richer web-based meeting rooms, media tools, and AI-assisted workspaces—experiences where one persistent control surface can be more valuable than another panel in the main layout.

Table of contents

  1. What is Document Picture-in-Picture?
  2. Which product problems does it solve?
  3. How should an app create a PiP window?
  4. How do state and styling work across windows?
  5. What are the security and UX constraints?
  6. How should teams ship it safely?

What is Document Picture-in-Picture?

Document Picture-in-Picture lets a top-level web page open an always-on-top window containing arbitrary HTML, CSS, and JavaScript. Unlike the familiar video Picture-in-Picture API, it is not restricted to one <video> element and browser-supplied controls. The Document PiP specification defines a full document in a separate window; the window is still tied to the opener, remains same-origin, and cannot navigate away.

That distinction changes the design space. A conferencing app can keep participant tiles and mute controls visible while a user edits a document. A transcription product can hold a live timer and record button above other work. A developer tool can pin a build status or a tiny task queue without turning the whole interface into a sticky-sidebar contest.

The API entry point is window.documentPictureInPicture. Calling requestWindow() resolves with the new window, which can receive DOM content. Chrome’s implementation guide and the MDN API reference are useful complements to the specification when planning real-world behaviour.

Document PiP is not a replacement for multi-window desktop software. It is intentionally constrained: one PiP window per tab, no control over screen position, no navigation, and no persistence after the originating page disappears. Those constraints are a feature. They preserve a clear relationship between the companion window and the page that created it.

Which product problems does Document PiP solve?

Document PiP is best when information needs to remain visible while the user’s attention moves elsewhere. The content should be compact, glanceable, and useful without making the user manage another full app window.

Video and collaboration controls

This is the clearest case. A call UI can surface the active speaker, camera preview, captions, or a small set of meeting actions. Traditional <video> PiP keeps media visible but cannot provide a coherent custom control surface. Document PiP can.

Timers, capture tools, and live status

Think recording timers, focus sessions, customer-support availability, an incident clock, or an upload monitor. These interfaces often need to be visible but should not hijack the main task. A Document PiP window is less intrusive than an overlay and less fragile than a notification stream.

Companion interfaces for dense web apps

Designers often solve density by growing persistent sidebars. That can make the primary screen worse for everyone. A user-invoked companion view creates a more honest choice: keep the main canvas uncluttered, then provide an optional floating surface for the people who genuinely need it.

This works particularly well alongside modern browser-native UI capabilities. For an in-page fallback, a Popover API or anchored control can keep the interaction local; for navigation changes, the View Transition API can make the main app feel continuous. Document PiP is for the smaller class of tasks where “always visible beyond this tab” is actually the requirement.

How should an app create a PiP window?

Start from an explicit user gesture, feature-detect the API, and handle the failure path. A button is better than silently creating a floating window: it gives users agency and aligns with the browser’s permission and popup expectations.

js
const openButton = document.querySelector('#open-companion');

openButton.addEventListener('click', async () => {
  if (!('documentPictureInPicture' in window)) {
    showInPageCompanion();
    return;
  }

  try {
    const pipWindow = await window.documentPictureInPicture.requestWindow({
      width: 360,
      height: 220,
    });

    mountCompanion(pipWindow);
  } catch (error) {
    console.warn('Could not open companion window', error);
    showInPageCompanion();
  }
});

width and height are requests, not a promise of precise placement. The browser retains control over where the always-on-top window goes. That is important both for user control and for preventing a site from impersonating desktop or browser chrome.

The mountCompanion function should render a purpose-built UI. Resist the temptation to move an entire application shell into PiP. A good companion has a clear job: show the current call, expose three or four actions, or display a live status. It should not become a second main window with its own unpredictable navigation state.

How do state and styling work across windows?

The PiP window is a distinct document, so it does not automatically inherit your page’s styles or DOM nodes. The reliable mental model is: one state model, two rendering targets. Keep data and business logic in shared application state, then mount a small component tree in the PiP document.

For framework apps, that commonly means creating a root against an element inside pipWindow.document.body. For plain JavaScript, create a container and render directly into it. Copy linked stylesheets where same-origin access is available, then add a small PiP-specific stylesheet for dimensions, focus rings, and reduced controls.

js
function mountCompanion(pipWindow) {
  for (const sheet of document.styleSheets) {
    if (sheet.href) {
      const link = pipWindow.document.createElement('link');
      link.rel = 'stylesheet';
      link.href = sheet.href;
      pipWindow.document.head.append(link);
    }
  }

  const root = pipWindow.document.createElement('div');
  root.id = 'companion-root';
  pipWindow.document.body.append(root);
  renderCompanion(root, appStore.getSnapshot());

  const unsubscribe = appStore.subscribe((state) => {
    renderCompanion(root, state);
  });

  pipWindow.addEventListener('pagehide', () => {
    unsubscribe();
    restoreInPageControls();
  }, { once: true });
}

Avoid assuming that every stylesheet is readable. Cross-origin stylesheets can be subject to browser security restrictions, so copying <link> elements is generally more robust than iterating cssRules. Also test font loading and colour-scheme behaviour: a tiny always-on-top surface makes unreadable contrast or delayed fonts especially obvious.

The cleanup handler matters. The user can close the PiP window from browser UI at any time, so the app must not leave stale subscriptions, orphaned media controls, or a “close companion” button that points at a closed window. Treat pagehide as the lifecycle boundary.

What are the security and UX constraints?

Document PiP is a secure-context API, which means production usage requires HTTPS. The specification also prevents a site from freely positioning the window, navigating it, or making it fullscreen. Browsers must preserve signals about the controlling origin, precisely because a window that floats above other apps could otherwise be used for UI spoofing.

Those rules produce sensible product guidance:

  • Never imitate operating-system dialogs, browser permission prompts, or payment UI.
  • Keep actions obvious and reversible; a clear “Return to tab” or “Open full controls” affordance helps.
  • Do not rely on PiP for an action that must be discoverable or accessible to every user.
  • Make keyboard focus, labels, and contrast first-class. A companion window is still a web document.
  • Do not put secrets, payment confirmations, or irreversible destructive actions into a reduced floating UI without a deliberate confirmation flow.

The same defensive mindset applies to the rest of the browser surface. If the companion renders user-controlled HTML, follow protections such as Trusted Types rather than letting a new window multiply the impact of an XSS mistake.

How should teams ship Document PiP safely?

Ship it as progressive enhancement, not an architecture dependency. Browser support evolves, and a useful product must work when documentPictureInPicture is absent, blocked, or closed immediately by the user. The fallback can be an in-page dock, a popover, or simply a well-designed compact mode.

Use this rollout checklist:

  1. Pick one narrow workflow. Start with a timer, call controls, or monitoring status—not a general “open in PiP” switch for the whole app.
  2. Define parity. Decide what the in-page fallback does before writing the PiP version. The fallback should retain the essential task, not merely display an apology.
  3. Centralise state. The main tab remains the source of truth. The PiP renderer subscribes and cleans up; it does not become an independent state silo.
  4. Test lifecycle edges. Close the PiP window, refresh the opener, navigate within the app, switch themes, lose network access, and open a second companion request.
  5. Measure voluntary use. Track opt-in, duration, fallback use, and return-to-tab actions. These signals are more useful than raw feature opens.
  6. Respect performance. A second rendering target has a cost. Keep the component small, avoid duplicate polling, and cancel work when it closes—patterns that pair naturally with AbortSignal.any().

There is a broader lesson here. The best web-platform features do not always replace framework patterns; often they let teams remove bespoke workarounds. Document PiP can replace a brittle popup strategy or an oversized sticky panel, but only when the product truly benefits from persistent, user-controlled visibility.

FAQ

Does Document Picture-in-Picture work like video PiP?

No. Video PiP displays a video element with limited browser-controlled UI. Document PiP opens a small always-on-top window that can contain ordinary same-origin web content and custom controls.

Can a Document PiP window remain open after the tab closes?

No. It is tied to its opener and does not outlive the opening document. Design it as a companion, not as a standalone application window.

Should every web app add a PiP button?

No. Add it when a compact, persistent view solves a real multitasking problem. An in-page panel is usually simpler for information that does not need to stay visible outside the tab.

What is the safest fallback?

Use an in-page dock or popover that provides the same essential action. Feature-detect before calling the API and keep the main application state independent of the rendering location.

Sources

Frequently Asked Questions

Does Document PiP work like video PiP?

No. It supports a full same-origin document window rather than a single video element.

Can the PiP window outlive its opener?

No. It closes when the opening document goes away.

Should Document PiP have a fallback?

Yes. Use an in-page dock or popover for browsers without support.