Skip to content
FrameworkStyle

media-cast-button

Accessible Cast toggle button with state reflection and keyboard support

Anatomy

<media-cast-button></media-cast-button>

Behavior

Toggles a Google Cast session. Clicking the button while disconnected opens the Cast device picker; clicking while connected ends the session.

The button does nothing when availability is not 'available' — for example, when no Chromecast is on the network, or on browsers that don’t support Cast.

Styling

Style based on cast state and availability:

/* During an active session */
media-cast-button[data-cast-state="connected"] {
  color: blue;
}

/* Hide when Cast is unsupported (non-Chromium browsers) */
media-cast-button[data-availability="unsupported"] {
  display: none;
}

Accessibility

Renders a <button> with an automatic aria-label:

Cast state Default label
'disconnected' ”Start casting”
'connecting' ”Connecting”
'connected' ”Stop casting”

Override with the label prop. Keyboard activation: Enter / Space.

Examples

Basic Usage

Stop casting Start casting
<video-player class="video-player">
    <media-container>
        <hls-video
            src="https://stream.mux.com/BV3YZtogl89mg9VcNBhhnHm02Y34zI1nlMuMQfAbl3dM.m3u8"
            autoplay
            muted
            playsinline
            loop
        ></hls-video>
        <media-cast-button class="media-cast-button">
            <span class="connected">Stop casting</span>
            <span class="disconnected">Start casting</span>
        </media-cast-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
castState 'disconnected' | 'connecting' | 'conn...
availability 'available' | 'unavailable' | 'unsupp...
label string

Data attributes

Attribute Type Details
data-cast-state 'disconnected' | 'connecting' | 'conn...
data-availability 'available' | 'unavailable' | 'unsupp...