FrameworkStyle

media-captions-button

Accessible captions toggle button with availability detection and state reflection

Anatomy

<media-captions-button></media-captions-button>

Behavior

Toggles captions and subtitles on and off. The button checks the media’s text track list for tracks with kind="captions" or kind="subtitles" and reflects availability via data-availability.

When no caption or subtitle tracks are present, data-availability="unavailable" is set. Use this to hide the button when there are no tracks to toggle.

Styling

Style the button based on active state:

media-captions-button[data-active] .icon-on { display: inline; }
media-captions-button:not([data-active]) .icon-off { display: inline; }

Hide when no caption tracks are available:

media-captions-button[data-availability="unavailable"] {
  display: none;
}

Accessibility

Renders a <button> with an automatic aria-label: “Disable captions” when active, “Enable captions” when inactive. Override with the label prop. Keyboard activation: Enter / Space.

Examples

Basic Usage

Captions Off Captions On
<video-player class="html-captions-button-basic">
    <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" />
        </video>
        <media-captions-button class="html-captions-button-basic__button">
            <span class="show-when-active">Captions Off</span>
            <span class="show-when-inactive">Captions On</span>
        </media-captions-button>
    </media-container>
</video-player>

API Reference

Props

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

State

State is reflected as data attributes for CSS styling.

Property Type
availability 'available' | 'unavailable'
subtitlesShowing boolean

Data attributes

Attribute Type
data-active
data-availability 'available' | 'unavailable'