--- url: "https://web.dev/articles/media/picture-in-picture" titulek: "How to add Picture-in-Picture to video controls | Media patterns | web.dev" h1: "How to add Picture-in-Picture to video controls Stay organized with collections Save and categorize content based on your preferences." popis: "" jazyk: "en" kanonicka: "https://web.dev/articles/media/picture-in-picture" drobecky: ["Media patterns", "How to add Picture-in-Picture to video controls"] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-14 01:48:27" znaku: 5571 slov: 669 kodovani: "iso-8859-2" sha256: "f58ee868465a88289c8e0278cb61c5eb6a1c277bc10d85d2f05bc34c0fde7a82" --- How to add Picture-in-Picture to video controls Stay organized with collections Save and categorize content based on your preferences. François Beaufort The modern way The [Picture-in-Picture (PiP) Web API](https://w3c.github.io/picture-in-picture/) allows websites to create a floating video window always on top of other windows so that users may continue consuming media while they interact with other content sites or applications on their device. The example below shows you how to create a button that users can use to toggle Picture-in-Picture on a video. `togglePipButton.addEventListener("click", async (event) => { togglePipButton.disabled = true; try { if (video !== document.pictureInPictureElement) { await video.requestPictureInPicture(); } else { await document.exitPictureInPicture(); } } finally { togglePipButton.disabled = false; } }); video.addEventListener("enterpictureinpicture", (event) => { togglePipButton.classList.add("on"); }); video.addEventListener("leavepictureinpicture", (event) => { togglePipButton.classList.remove("on"); }); /* Feature detection */ if ("pictureInPictureEnabled" in document) { // Set button ability depending on whether Picture-in-Picture can be used. setPipButton(); video.addEventListener("loadedmetadata", setPipButton); video.addEventListener("emptied", setPipButton); } else { // Hide button if Picture-in-Picture is not supported. togglePipButton.hidden = true; } function setPipButton() { togglePipButton.disabled = video.readyState === 0 || !document.pictureInPictureEnabled || video.disablePictureInPicture; }` The classic way Before the availability of the Picture-in-Picture Web API, there was no way to create a floating video window always on top of other windows. Playing the video on top of other elements on the web page is possible though with CSS. The example below shows you how to display your video on top of other elements at the bottom right corner of your web page when the user clicks a button. `toggleFakePipButton.addEventListener("click", (event) => { video.classList.toggle("fake-pip"); });``/* Place the video in the bottom right corner on top of everything else via CSS. */ video.fake-pip { position: fixed; z-index: 1000; bottom: 10px; right: 10px; }` Further reading [W3C Picture-in-Picture Specification](https://w3c.github.io/picture-in-picture/) [Watch video using Picture-in-Picture](https://developer.chrome.com/blog/watch-video-using-picture-in-picture) [MDN Picture-in-Picture API](https://developer.mozilla.org/docs/Web/API/Picture-in-Picture_API) HTML `