PiPButton
A button component for entering and exiting picture-in-picture mode
Anatomy
<PiPButton /><media-pip-button></media-pip-button>Behavior
Toggles picture-in-picture (PiP) mode. Detects platform support through availability — when PiP is "unsupported", the toggle does nothing.
Styling
You can style the button based on PiP state:
/* In PiP mode */
media-pip-button[data-pip] {
background: red;
}Consider hiding the button when unsupported:
media-pip-button[data-availability="unsupported"] {
display: none;
}Accessibility
Renders a <button> with an automatic aria-label: “Enter PiP” or “Exit PiP”. Override with the label prop. Keyboard activation: Enter / Space.
Examples
Basic Usage
import { createPlayer, features, PiPButton, Video } from '@videojs/react';
import './BasicUsage.css';
const Player = createPlayer({ features: [...features.video] });
export default function BasicUsage() {
return (
<Player.Provider>
<Player.Container className="react-pip-button-basic">
<Video
src="https://stream.mux.com/lhnU49l1VGi3zrTAZhDm9LUUxSjpaPW9BL4jY25Kwo4/highest.mp4"
autoPlay
muted
playsInline
loop
/>
<PiPButton
className="react-pip-button-basic__button"
render={(props, state) => <button {...props}>{state.pip ? 'Exit PiP' : 'Enter PiP'}</button>}
/>
</Player.Container>
</Player.Provider>
);
}
.react-pip-button-basic {
position: relative;
}
.react-pip-button-basic video {
width: 100%;
}
.react-pip-button-basic__button {
padding-block: 8px;
position: absolute;
bottom: 10px;
right: 10px;
background: rgba(255, 255, 255, 0.7);
backdrop-filter: blur(10px);
color: black;
border: 1px solid rgba(255, 255, 255, 0.3);
border-radius: 9999px;
padding-inline: 20px;
cursor: pointer;
}
<video-player class="html-pip-button-basic">
<video
src="https://stream.mux.com/lhnU49l1VGi3zrTAZhDm9LUUxSjpaPW9BL4jY25Kwo4/highest.mp4"
autoplay
muted
playsinline
loop
></video>
<media-pip-button class="html-pip-button-basic__button">
<span class="show-when-pip">Exit PiP</span>
<span class="show-when-not-pip">Enter PiP</span>
</media-pip-button>
</video-player>
.html-pip-button-basic {
display: block;
position: relative;
}
.html-pip-button-basic video {
width: 100%;
}
.html-pip-button-basic__button {
padding-block: 8px;
position: absolute;
bottom: 10px;
right: 10px;
background: rgba(255, 255, 255, 0.7);
backdrop-filter: blur(10px);
color: black;
border: 1px solid rgba(255, 255, 255, 0.3);
border-radius: 9999px;
padding-inline: 20px;
cursor: pointer;
}
.html-pip-button-basic__button .show-when-pip {
display: none;
}
.html-pip-button-basic__button .show-when-not-pip {
display: none;
}
.html-pip-button-basic__button[data-pip] .show-when-pip {
display: inline;
}
.html-pip-button-basic__button:not([data-pip]) .show-when-not-pip {
display: inline;
}
import '@videojs/html/video/player';
import '@videojs/html/ui/pip-button';
API Reference
Props
| Prop | Type | Default | |
|---|---|---|---|
disabled | boolean | false | |
| |||
label | string | function | '' | |
| |||
State
State is accessible via the
render, className, and style props.
State is reflected as data attributes for CSS styling.
| Property | Type | |
|---|---|---|
availability | 'available' | 'unavailable' | 'unsupported' | |
| ||
pip | boolean | |
| ||
Data attributes
| Attribute | Description |
|---|---|
data-pip | Present when picture-in-picture mode is active. |
data-availability | Indicates picture-in-picture availability (available or unsupported). |