Skip to content

ReferenceDisplay

media-tooltip

A tooltip component for displaying contextual labels on hover and focus

Import

import '@videojs/html/ui/tooltip';
import '@videojs/html/ui/tooltip-group';
import '@videojs/html/ui/tooltip-label';
import '@videojs/html/ui/tooltip-shortcut';

Anatomy

<media-tooltip-group>
  <button commandfor="my-tooltip">Hover me</button>
  <media-tooltip id="my-tooltip">
    <media-tooltip-label>Label text</media-tooltip-label>
    <media-tooltip-shortcut>K</media-tooltip-shortcut>
  </media-tooltip>
</media-tooltip-group>

Behavior

Displays a short label anchored to a trigger element. Opens after a configurable delay (default 600ms) on hover or immediately on focus. Closes when the pointer leaves or focus moves away, with an optional closeDelay.

The side and align props control the preferred placement relative to the trigger. When the preferred side overflows the positioning boundary, the tooltip uses the opposite side if it has more space. Positioning uses CSS Anchor Positioning where supported, with a JavaScript measurement fallback.

The <media-tooltip> element is the popup itself. Link it to a trigger using the commandfor attribute on any button, pointing to the tooltip’s id. The element discovers its trigger automatically and manages open/close state and positioning. Wrap tooltip trigger/popup pairs in <media-tooltip-group> to coordinate timing — the group’s delay, close-delay, and timeout attributes control shared timing for all contained tooltips.

Tooltips inside a player container also observe its popup group. By default, a tooltip does not open—or closes if already open—while a menu or popover attached to the same trigger is open. Set sticky when the tooltip should remain visible with that trigger’s popup.

<media-tooltip-group> coordinates tooltip delay timing only; it does not replace the container’s popup group.

Styling

Use CSS custom properties for positioning offsets:

media-tooltip {
  --media-tooltip-side-offset: 8px;
  --media-tooltip-align-offset: 0px;
  --media-tooltip-boundary-offset: 8px;
}

Style based on open state, rendered side, and transition phases. data-side reflects the rendered side and can differ from the preferred side prop after collision handling:

media-tooltip[data-open] {
  display: block;
}
media-tooltip[data-starting-style] {
  opacity: 0;
}
media-tooltip[data-ending-style] {
  opacity: 0;
}
media-tooltip[data-side="top"] {
  transform-origin: bottom center;
}
media-tooltip[data-side="bottom"] {
  transform-origin: top center;
}

Accessibility

Tooltips are visual-only, supplementary labels. The popup renders with role="presentation" and is not referenced by the trigger with aria-describedby. Give the trigger its own accessible name instead of relying on tooltip content. Built-in media buttons already expose a state-aware aria-label, and their tooltips reuse that translated label. Tooltips still open on focus so keyboard users who can see the label receive the same visual hint.

Examples

Basic Usage

Tooltip content
<div class="demo">
  <button type="button" commandfor="tooltip-demo" class="trigger">Hover me</button>
  <media-tooltip id="tooltip-demo" class="media-tooltip"> Tooltip content </media-tooltip>
</div>

Grouping

Wrap tooltip trigger/popup pairs in <media-tooltip-group> to coordinate timing. The group’s delay, close-delay, and timeout attributes control shared timing for all contained tooltips.

Play video Mute audio Enter fullscreen
<media-tooltip-group class="demo">
  <button type="button" commandfor="tooltip-play" class="trigger">Play</button>
  <media-tooltip id="tooltip-play" class="media-tooltip">Play video</media-tooltip>

  <button type="button" commandfor="tooltip-mute" class="trigger">Mute</button>
  <media-tooltip id="tooltip-mute" class="media-tooltip">Mute audio</media-tooltip>

  <button type="button" commandfor="tooltip-fullscreen" class="trigger">Fullscreen</button>
  <media-tooltip id="tooltip-fullscreen" class="media-tooltip">Enter fullscreen</media-tooltip>
</media-tooltip-group>

API Reference

media-tooltip-group

Props

PropTypeDefaultDetails
closeDelay
attribute close-delay
number—
delaynumber—
timeoutnumber—

media-tooltip

Props

PropTypeDefaultDetails
align'start' | 'center' | 'end''center'
boundary'viewport' | 'container' | string & {}—
closeDelay
attribute close-delay
number0
defaultOpen
attribute default-open
booleanfalse
delaynumber600
disabledbooleanfalse
disableHoverablePopup
attribute disable-hoverable-popup
booleantrue
openbooleanfalse
side'top' | 'bottom' | 'left' | 'right''top'
stickybooleanfalse

State

State is reflected as data attributes for CSS styling.

PropertyTypeDetails
transitionStartingboolean
transitionEndingboolean
openboolean
status'idle' | 'starting' | 'ending'
side'top' | 'bottom' | 'left' | 'right'
align'start' | 'center' | 'end'

Data attributes

AttributeTypeDetails
data-open—
data-side'top' | 'bottom' | 'left' | 'right'
data-align'start' | 'center' | 'end'

CSS custom properties

VariableDescription
--media-tooltip-side-offsetDistance between the popup and the trigger along the side axis.
--media-tooltip-align-offsetDistance between the popup and the trigger along the alignment axis.
--media-tooltip-boundary-offsetMinimum distance between the popup and the positioning boundary.
--media-tooltip-anchor-widthThe anchor element's width.
--media-tooltip-anchor-heightThe anchor element's height.
--media-tooltip-available-widthAvailable width between the trigger and the boundary edge.
--media-tooltip-available-heightAvailable height between the trigger and the boundary edge.

Events

EventDescription
open-changeFired when the tooltip's open state changes.

media-tooltip-label

Label region inside media-tooltip; parent syncs text from the trigger when linked to a media button.

Data attributes

AttributeTypeDetails
data-open—
data-side'top' | 'bottom' | 'left' | 'right'
data-align'start' | 'center' | 'end'

media-tooltip-shortcut

Shortcut hint inside media-tooltip. CSS skins: class="media-tooltip__kbd"; Tailwind skins: class from popup.tooltipShortcut.

Data attributes

AttributeTypeDetails
data-open—
data-side'top' | 'bottom' | 'left' | 'right'
data-align'start' | 'center' | 'end'