Skip to content

ReferenceDisplay

media-title

Displays the resolved content title for the current media

Import

import '@videojs/html/ui/title';

Anatomy

<media-title></media-title>

Behavior

The element renders the resolved title directly as text and owns that text: it replaces any authored content whenever the title updates. Set the title on the player instead.

<video-player content-title="Big Buck Bunny">
  <video src="video.mp4"></video>
  <media-title></media-title>
</video-player>

A title can come from two places. The player uses the first one that has a value:

  1. The title you set on the player.
  2. The title the media reports about itself.

If neither has a value, there is nothing to show and the title hides itself.

The title is player input, not player state, so change it the way you set it in the first place. The store exposes the resolved title to read, and nothing to write. That resolution belongs to the metadata feature, which the video and audio presets include.

title already means the tooltip on an element, so the player takes the title as content-title, reflected by the contentTitle property:

const player = document.querySelector("video-player");

player.contentTitle = "Sintel";

Set it to null to hand the title back to the media.

The component exposes data-visible while controls are visible. Use that hook to animate the title with the controls.

Styling

When no title resolves, the element sets the native hidden attribute and data-hidden, so it takes up no space and a background or gradient never sits over empty space.

To fade the title in and out with the controls, use the root’s data-visible attribute:

media-title {
  opacity: 0;
  transition: opacity 150ms ease-out;
}

media-title[data-visible] {
  opacity: 1;
}

Accessibility

The title is ordinary text, so it reaches assistive technology as content with no ARIA of its own. The native hidden attribute it sets when there is no title also removes it from the accessibility tree, so nothing is announced when there is nothing to announce.

Fading the title out with opacity leaves it readable by a screen reader while it is not painted. That is deliberate — the name of what is playing stays relevant whether or not the controls happen to be on screen.

The component does not name the player. To give the player region an accessible name, set aria-label or aria-labelledby on the container yourself.

Examples

Basic Usage

Play Pause
<video-player content-title="Big Buck Bunny">
  <media-container class="html-title-basic">
    <video src="https://stream.mux.com/BV3YZtogl89mg9VcNBhhnHm02Y34zI1nlMuMQfAbl3dM/highest.mp4" muted playsinline loop></video>
    <media-title class="html-title-basic__title"></media-title>
    <media-play-button class="html-title-basic__button">
      <span class="show-when-paused">Play</span>
      <span class="show-when-playing">Pause</span>
    </media-play-button>
  </media-container>
</video-player>

API Reference

State

State is reflected as data attributes for CSS styling.

PropertyTypeDetails
titlestring
hiddenboolean
visibleboolean

Data attributes

AttributeDescription
data-hiddenPresent when the element is hidden because no title is available.
data-visiblePresent while the player controls are visible.