Skip to content
FrameworkStyle

media-pip-button

Accessible picture-in-picture toggle button with keyboard support and state reflection

Anatomy

<media-pip-button></media-pip-button>

Behavior

Toggles picture-in-picture (PiP) mode. The button derives two state hooks from availability:

  • disabled (true when the API is available but not currently usable, or when the disabled prop is set) — sets aria-disabled="true" and data-disabled so the button stays focusable but does not activate.
  • hidden (true when PiP is "unsupported") — applies the native HTML hidden attribute on the custom element; the React component returns null.

Styling

You can style the button based on PiP state:

/* In PiP mode */
media-pip-button[data-pip] {
  background: red;
}

/* Non-interactive (disabled prop or temporarily unavailable) */
media-pip-button[data-disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

Unsupported environments hide the button automatically — the HTML element receives the native hidden attribute, and the React component returns null. No extra CSS is required.

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

Exit PiP Enter PiP
<video-player class="video-player">
    <media-container>
        <video
            src="https://stream.mux.com/BV3YZtogl89mg9VcNBhhnHm02Y34zI1nlMuMQfAbl3dM/highest.mp4"
            autoplay
            muted
            playsinline
            loop
        ></video>
        <media-pip-button class="media-pip-button">
            <span class="pip">Exit PiP</span>
            <span class="not-pip">Enter PiP</span>
        </media-pip-button>
    </media-container>
</video-player>

API Reference

Props

Prop Type Default Details
disabled boolean false
label string | function ''

State

State is reflected as data attributes for CSS styling.

Property Type Details
availability 'available' | 'unavailable' | 'unsupp...
disabled boolean
hidden boolean
pip boolean
label string

Data attributes

Attribute Type Details
data-pip
data-availability 'available' | 'unavailable' | 'unsupp...
data-disabled
data-hidden