JavaScript Document pictureInPictureElement Property

Beginner
⏱️ 12 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Limited availability
Instance property

What You’ll Learn

Document.pictureInPictureElement is a read-only instance property that returns the Element currently shown in picture-in-picture (PiP) mode, or null. Learn MDN’s exit helper, how it parallels fullscreenElement, video PiP workflows, and five examples with try-it labs.

01

Kind

Read-only property

02

Returns

Element | null

03

Active?

!== null

04

Exit

exitPictureInPicture

05

API

PiP / video

06

Status

Limited avail.

Introduction

Picture-in-picture mode lets users watch a video in a small floating window while continuing to browse the page. When PiP is active, scripts need to know which element is playing in that window—that is what document.pictureInPictureElement provides.

MDN: the read-only property returns the Element that is currently being presented in picture-in-picture mode in this document, or null if picture-in-picture mode is not currently in use.

💡
Parallel to fullscreen

Think of it like document.fullscreenElement: one property tells you whether a special presentation mode is on and which DOM element is involved.

Related Document tutorials: fullscreenElement, hidden, activeElement, Document constructor.

Understanding Document.pictureInPictureElement

A read-only instance property on Document. Its value is the element in PiP mode, or null when PiP is off.

  • ValueElement reference in PiP, or null (MDN).
  • Read-only — assigning does not throw; the setter is ignored (MDN no-op).
  • Null cases — no PiP active, or the PiP element belongs to an iframe (MDN).
  • Typical element — often an HTMLVideoElement after requestPictureInPicture().
  • Exit — pair with document.exitPictureInPicture() when truthy (MDN example).

📝 Syntax

JavaScript
document.pictureInPictureElement

Value

An Element object — or null when picture-in-picture mode is not in use for this document (MDN).

MDN example — exit PiP if active

JavaScript
function exitPictureInPicture() {
  if (document.pictureInPictureElement) {
    document.exitPictureInPicture();
  }
}

Check if PiP is active

JavaScript
const isPiP = document.pictureInPictureElement !== null;
console.log("PiP active?", isPiP);

⚡ Quick Reference

GoalCode / note
PiP element or nulldocument.pictureInPictureElement
Is PiP active?document.pictureInPictureElement !== null
Exit PiP (MDN)document.exitPictureInPicture()
Enter PiP (video)await video.requestPictureInPicture()
Sync UIenterpictureinpicture / leavepictureinpicture events
MDN statusLimited availability (not Baseline)

🔍 At a Glance

Four facts about document.pictureInPictureElement.

Type
Element|null

Read-only

Mode
PiP

Floating window

Active?
!== null

Status check

Status
limited

Not Baseline

📋 pictureInPictureElement vs fullscreenElement

pictureInPictureElementfullscreenElement
PresentationSmall floating PiP windowFull screen
Typical mediaVideo (most common)Video, canvas, div, etc.
Enter APIvideo.requestPictureInPicture()element.requestFullscreen()
Exit APIdocument.exitPictureInPicture()document.exitFullscreen()

Examples Gallery

Examples follow MDN Document: pictureInPictureElement. Try-it labs read the property safely; enter PiP from a user click where the browser supports it.

📚 Getting Started

Read the property and detect picture-in-picture mode.

Example 1 — Read When PiP Is Off

On a normal page, the property is null until PiP starts.

JavaScript
console.log(document.pictureInPictureElement);
// null when PiP is not active
console.log(document.pictureInPictureElement === null);
Try It Yourself

How It Works

null means no element from this document is currently in the PiP window.

Example 2 — MDN exitPictureInPicture() Helper

Only call exit when the property is truthy (MDN example).

JavaScript
function exitPictureInPicture() {
  if (document.pictureInPictureElement) {
    document.exitPictureInPicture();
  }
}

exitPictureInPicture(); // no-op when null
Try It Yourself

How It Works

Guarding on pictureInPictureElement avoids calling exit when PiP is already closed.

📈 Video PiP & Events

Enter PiP from a video and keep UI in sync.

Example 3 — Inspect the Active PiP Element

When PiP is on, read nodeName or id from the returned element.

JavaScript
const el = document.pictureInPictureElement;
if (el) {
  console.log(el.nodeName); // often "VIDEO"
  console.log(el.id);
} else {
  console.log("No PiP element");
}
Try It Yourself

How It Works

The same element reference you passed to requestPictureInPicture() is returned while PiP is active.

Example 4 — Enter PiP from a Video Click

Request PiP on user gesture; then the property points at the video.

JavaScript
const video = document.querySelector("#player");

async function togglePiP() {
  if (document.pictureInPictureElement) {
    await document.exitPictureInPicture();
  } else if (document.pictureInPictureEnabled) {
    await video.requestPictureInPicture();
  }
  console.log(document.pictureInPictureElement);
}
Try It Yourself

How It Works

Feature-detect with document.pictureInPictureEnabled before calling requestPictureInPicture().

Example 5 — Listen for PiP Enter / Leave Events

Update buttons when pictureInPictureElement changes.

JavaScript
function updatePiPUI() {
  const active = document.pictureInPictureElement !== null;
  console.log("PiP active?", active);
}

document.addEventListener("enterpictureinpicture", updatePiPUI);
document.addEventListener("leavepictureinpicture", updatePiPUI);
Try It Yourself

How It Works

Events fire on the document when PiP starts or ends—use them instead of polling the property.

🚀 Common Use Cases

  • Toggle PiP button — show “Exit PiP” when the property is not null.
  • Custom close control — MDN-style exitPictureInPicture() wrapper.
  • Analytics — log which video element entered PiP.
  • Accessibility — announce PiP state changes to screen readers.
  • Single PiP policy — ensure only one video uses PiP at a time.
  • Debugging — verify PiP state during media player development.

🧠 How Picture-in-Picture Status Works

1

User starts PiP

Click PiP UI or call video.requestPictureInPicture() from a gesture.

Enter
2

Property updates

document.pictureInPictureElement references the active element.

Set
3

Floating window plays media

User continues browsing while the PiP window stays on screen.

Play
4

Exit clears to null

exitPictureInPicture(), close button, or system UI resets the property to null.

📝 Notes

  • MDN: Limited availability (not Baseline) — no Deprecated / Experimental / Non-standard banner.
  • Assigning to the property is a no-op; it never throws, even in strict mode (MDN).
  • Returns null for iframe PiP elements in the parent document (MDN).
  • Pair with document.pictureInPictureEnabled before offering PiP controls.
  • Related: fullscreenElement, hidden, Document constructor.

Browser Support

Document.pictureInPictureElement is marked Limited availability on MDN (not Baseline). Feature-detect with pictureInPictureEnabled before production use. Logos use the shared browser-image-sprite.png sprite from this project.

Limited availability · Not Baseline

Document.pictureInPictureElement

Read-only Element in picture-in-picture mode, or null — Picture-in-Picture API status check.

Limited Check compat
Google Chrome Supported · Desktop & Android
Supported
Mozilla Firefox Supported in modern versions
Supported
Apple Safari Limited / platform-dependent PiP
Partial
Microsoft Edge Chromium PiP support
Supported
Opera Follow Chromium behavior
Supported
Internet Explorer No Picture-in-Picture API
Not supported
Document.pictureInPictureElement Limited availability

Bottom line: Use pictureInPictureElement !== null to detect PiP. Pair with requestPictureInPicture / exitPictureInPicture and enterpictureinpicture / leavepictureinpicture events.

Conclusion

Document.pictureInPictureElement tells you which element (if any) is playing in picture-in-picture mode. Check it before calling exitPictureInPicture(), mirror the pattern of fullscreenElement, and keep UI in sync with PiP events.

Continue with pictureInPictureEnabled, fullscreenElement, location, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Check document.pictureInPictureElement !== null
  • Feature-detect document.pictureInPictureEnabled
  • Start PiP only from a user gesture (click / tap)
  • Listen for enterpictureinpicture and leavepictureinpicture
  • Guard exitPictureInPicture() with a truthy property check (MDN)

❌ Don’t

  • Assign to pictureInPictureElement expecting to enter PiP
  • Assume PiP works in every browser (Limited availability)
  • Expect parent-document access to iframe PiP elements (MDN: null)
  • Auto-open PiP without user interaction
  • Poll the property in a tight loop instead of using events

Key Takeaways

Knowledge Unlocked

Five things to remember about pictureInPictureElement

Element or null — the PiP status property.

5
Core concepts
02

Active

!== null

Check
🚪03

Exit

exitPictureInPicture

MDN
🎥04

Enter

requestPiP

Video
🔄05

Events

enter / leave

Sync UI

❓ Frequently Asked Questions

The Element currently presented in picture-in-picture mode in this document, or null if PiP mode is not in use (MDN).
No. MDN marks it as Limited availability (not Baseline), but not Deprecated, Experimental, or Non-standard. Feature-detect before relying on it in production.
When picture-in-picture mode is not active, when there is no associated PiP element, or when the element is from an iframe (MDN).
No meaningful assignment. The property is read-only; modifying it does not throw even in strict mode — the setter is a no-operation and is ignored (MDN).
MDN example: if document.pictureInPictureElement is truthy, call document.exitPictureInPicture(). Users can also close PiP with browser UI.
fullscreenElement returns the element in fullscreen mode. pictureInPictureElement returns the element in the floating PiP window. They are separate APIs for different presentation modes.
Did you know?

MDN notes that although pictureInPictureElement is read-only, assigning to it does not throw—even in strict mode. The setter is ignored. To enter PiP, call requestPictureInPicture() on a video element instead.

Next: pictureInPictureEnabled

Learn how to check whether picture-in-picture mode is available.

pictureInPictureEnabled →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful