CSS Reference ยท Pseudo-classes
The :picture-in-picture pseudo-class
Reference for the CSS :picture-in-picture pseudo-class: style a video while it plays in a floating picture-in-picture window. Limited browser support.
The :picture-in-picture pseudo-class matches an element while it is shown in a picture-in-picture window: the small floating video window that stays on top of other apps. The usual target is a <video> element.
When a video is moved to the floating window, the space it leaves in the page often looks empty. This selector lets you replace the video with a placeholder or dim the poster in the meantime.
Support is limited, and the picture-in-picture feature itself may be unavailable in a sandboxed preview. Treat this as an enhancement.
video:picture-in-picture { opacity: 0.3; }
Try it
Syntax
:picture-in-picture { /* declarations */ }
No arguments; specificity (0,1,0).
Syntax and arguments
| Part | Description |
|---|---|
:picture-in-picture |
Matches the element that is currently in the picture-in-picture window. |
video:picture-in-picture |
The usual form, limited to videos. |
:not(:picture-in-picture) |
The element in its normal place in the page. |
Usage notes
- The video moves, the element stays. The
<video>element remains in the DOM; only its rendering moves. The match lasts while the floating window is open. - Start it from script or the browser UI. Scripts call
requestPictureInPicture()after a user gesture; browsers also offer a button in the video's controls unless you setdisablepictureinpicture. - Fill the gap. Pair it with a poster, a message such as "Playing in a floating window", or a lowered opacity so the layout does not look broken.
- Document picture-in-picture (arbitrary HTML in a floating window) is a different API and does not use this selector.
- Guard your rules. Use
@supports selector(:picture-in-picture)and test in the browsers you target.
Browser support
Limited: available only in some browsers and not Baseline. Check a current support table before depending on it.
Related
:playingโ playing media:fullscreenโ fullscreen element:modalโ modal state- Lessons: Feature queries, Pseudo-classes