Skip to content
FrameworkStyle

media-captions-radio-group

A menu radio group for selecting caption and subtitle tracks

Creates radio items from the player text track state and selects the showing caption or subtitle track.

Anatomy

<media-captions-radio-group>
  <template>
    <media-menu-radio-item>
      <span data-part="label"></span>
      <media-menu-item-indicator></media-menu-item-indicator>
    </media-menu-radio-item>
  </template>
</media-captions-radio-group>

Behavior

The group is available when the configured media exposes at least one caption or subtitle track. The first generated option is Off; selecting it hides captions. Track labels use the track label, then language, then kind. Pass formatTrack to customize the visible labels.

<media-captions-radio-group> generates <media-menu-radio-item> children, including the Off item. Add an optional <template> with a single <media-menu-radio-item> to customize each generated item.

Styling

Attribute Values Description
data-active Present / absent Present when captions are enabled.
data-disabled Present / absent Present when track selection is disabled.
data-availability "available" / "unavailable" Whether caption or subtitle tracks are available.
media-captions-radio-group[data-availability="unavailable"] {
  display: none;
}

Accessibility

The group uses the menu radio group pattern.

The element receives an accessible label from the label property or defaults to Enable captions / Disable captions based on the current state.

Examples

Basic usage

<video-player class="video-player">
    <media-container>
        <video
            src="https://stream.mux.com/BV3YZtogl89mg9VcNBhhnHm02Y34zI1nlMuMQfAbl3dM/highest.mp4"
            autoplay
            muted
            playsinline
            loop
        >
            <track kind="captions" src="/docs/demos/captions-button/captions.vtt" srclang="en" label="English" />
            <track kind="subtitles" src="/docs/demos/captions-button/captions.vtt" srclang="es" label="Spanish" />
        </video>
        <div class="menu-bar">
            <button type="button" commandfor="captions-menu" class="settings-trigger">Captions</button>
            <media-menu id="captions-menu" side="top" align="end" class="menu">
                <media-captions-radio-group class="menu-group" label="Captions">
                    <template>
                        <media-menu-radio-item class="menu-item">
                            <span data-part="label"></span>
                            <media-menu-item-indicator force-mount class="menu-indicator"></media-menu-item-indicator>
                        </media-menu-radio-item>
                    </template>
                </media-captions-radio-group>
            </media-menu>
        </div>
    </media-container>
</video-player>

API Reference

Props

PropTypeDefaultDetails
disabledbooleanfalse
formatTrackText) | functionformatTrackLabel
labelText | string | Text) | function''

State

State is reflected as data attributes for CSS styling.

PropertyTypeDetails
tracksCaptionsRadioGroupTrack[]
valuestring
disabledboolean
availability'available' | 'unavailable'
subtitlesShowingboolean
labelText | string

Data attributes

AttributeTypeDetails
data-active
data-disabled
data-availability'available' | 'unavailable'