FrameworkStyle

media-time

Components for displaying and composing media time information

Anatomy

<media-time-group>
  <media-time type="current"></media-time>
  <media-time-separator></media-time-separator>
  <media-time type="duration"></media-time>
</media-time-group>

Behavior

Three display types — current, duration, and remaining — in digital format with smart padding:

  • Hours are never padded (1:05:30, not 01:05:30)
  • Minutes are padded when hours are shown (1:05:30, but 5:30)
  • Seconds are always padded (1:05, not 1:5)

Hour display is triggered when either the current value or the duration exceeds 1 hour, ensuring consistency within a Group. Remaining time displays a negative sign (customizable via the negativeSign prop).

Styling

The negative sign is rendered inside <span aria-hidden="true"> and can be hidden with CSS:

[data-type="remaining"] > span[aria-hidden] {
  display: none;
}

Accessibility

Each <media-time> has:

  • aria-label for the static role label (“Current time”, “Duration”, “Remaining”)
  • aria-valuetext for the dynamic human-readable time (“1 minute, 30 seconds”)

No aria-live region is used — time updates too frequently and might overwhelm screen readers. The separator is aria-hidden="true" since screen readers already hear each time value separately. The negative sign is also aria-hidden because aria-valuetext already conveys “remaining”. In React, <time datetime> provides machine-readable time for parsers.

Examples

Current Time

<video-player class="html-time-current-time">
    <video
        src="https://stream.mux.com/lhnU49l1VGi3zrTAZhDm9LUUxSjpaPW9BL4jY25Kwo4/highest.mp4"
        autoplay
        muted
        playsinline
        loop
    ></video>
    <media-time class="html-time-current-time__value" type="current"></media-time>
</video-player>

Current / Duration

<video-player class="html-time-current-duration">
    <video
        src="https://stream.mux.com/lhnU49l1VGi3zrTAZhDm9LUUxSjpaPW9BL4jY25Kwo4/highest.mp4"
        autoplay
        muted
        playsinline
        loop
    ></video>
    <media-time-group class="html-time-current-duration__group">
        <media-time type="current"></media-time>
        <media-time-separator></media-time-separator>
        <media-time type="duration"></media-time>
    </media-time-group>
</video-player>

Remaining

<video-player class="html-time-remaining">
    <video
        src="https://stream.mux.com/lhnU49l1VGi3zrTAZhDm9LUUxSjpaPW9BL4jY25Kwo4/highest.mp4"
        autoplay
        muted
        playsinline
        loop
    ></video>
    <media-time class="html-time-remaining__value" type="remaining"></media-time>
</video-player>

Custom Separator

of
<video-player class="html-time-custom-separator">
    <video
        src="https://stream.mux.com/lhnU49l1VGi3zrTAZhDm9LUUxSjpaPW9BL4jY25Kwo4/highest.mp4"
        autoplay
        muted
        playsinline
        loop
    ></video>
    <media-time-group class="html-time-custom-separator__group">
        <media-time type="current"></media-time>
        <media-time-separator> of </media-time-separator>
        <media-time type="duration"></media-time>
    </media-time-group>
</video-player>

Custom Negative Sign

<video-player class="html-time-custom-negative-sign">
    <video
        src="https://stream.mux.com/lhnU49l1VGi3zrTAZhDm9LUUxSjpaPW9BL4jY25Kwo4/highest.mp4"
        autoplay
        muted
        playsinline
        loop
    ></video>
    <media-time
        class="html-time-custom-negative-sign__value"
        type="remaining"
        negative-sign="~"
    ></media-time>
</video-player>

API Reference

media-time

Displays a formatted time value (current, duration, or remaining).

Props

Prop Type Default
label string | function ''
negativeSign string '-'
type 'current' | 'duration' | 'remaining' 'current'

State

State is reflected as data attributes for CSS styling.

Property Type
type 'current' | 'duration' | 'remaining'
seconds number
negative boolean
text string
phrase string
datetime string

Data attributes

Attribute Description
data-type The type of time being displayed.

media-time-group

Container for composed time displays. Renders a <span> element.

media-time-separator

Divider between time values. Hidden from screen readers.

VideoJS