<media-time-range>

The <media-time-range> component is used to indicate the current time position in the timeline of the media, and provides controls to seek to a new time in the media.

Hovering over the time range will show a preview time code by default, and if a track with a thumbnails VTT file is configured a preview thumbnail will be shown.

<media-controller>
  <video
    playsinline muted crossorigin
    slot="media"
    src="https://stream.mux.com/A3VXy02VoUinw01pwyomEO3bHnG4P32xzV7u1j1FSzjNg/low.mp4"
  ></video>
  <media-control-bar>
    <media-time-range></media-time-range>
  </media-control-bar>
</media-controller>

Adding a metadata text track labelled “thumbnails” (<track default label="thumbnails" kind="metadata" src="">) with a valid VTT file as src will enable the preview thumbnails on hover functionality.

<media-controller>
  <video 
    playsinline muted crossorigin
    slot="media"
    src="https://stream.mux.com/A3VXy02VoUinw01pwyomEO3bHnG4P32xzV7u1j1FSzjNg/low.mp4"
  >
    <track
      default label="thumbnails" kind="metadata"
      src="https://image.mux.com/A3VXy02VoUinw01pwyomEO3bHnG4P32xzV7u1j1FSzjNg/storyboard.vtt"
    >
  </video>
  <media-control-bar>
    <media-time-range></media-time-range>
  </media-control-bar>
</media-controller>

Add a time display component in the current slot that will slide along the timeline as the video progresses.

<media-controller>
  <video
    playsinline muted crossorigin
    slot="media"
    src="https://stream.mux.com/A3VXy02VoUinw01pwyomEO3bHnG4P32xzV7u1j1FSzjNg/low.mp4"
  ></video>
  <media-control-bar>
    <media-time-range>
      <media-time-display slot="current"></media-time-display>
    </media-time-range>
  </media-control-bar>
</media-controller>

Set the preview slot to an empty element to remove the default preview elements.

<media-controller>
  <video
    playsinline muted crossorigin
    slot="media"
    src="https://stream.mux.com/A3VXy02VoUinw01pwyomEO3bHnG4P32xzV7u1j1FSzjNg/low.mp4"
  ></video>
  <media-control-bar>
    <media-time-range>
      <span slot="preview"></span>
    </media-time-range>
  </media-control-bar>
</media-controller>

The <media-time-range> consists of several elements including an <input type="range"> element which can be tricky to style across browsers but the <media-time-range> component comes with targeted CSS variables that make this a breeze.

<style>
  media-time-range {
    --media-control-background: transparent;
    --media-control-hover-background: transparent;
    --media-range-track-border-radius: 3px;
    --media-range-thumb-opacity: .7;
    --media-preview-time-margin: 0 0 -15px;
  }
</style>
<media-controller>
  <video
    playsinline muted crossorigin
    slot="media"
    src="https://stream.mux.com/A3VXy02VoUinw01pwyomEO3bHnG4P32xzV7u1j1FSzjNg/low.mp4"
  ></video>
  <media-control-bar>
    <media-time-range></media-time-range>
  </media-control-bar>
</media-controller>

Discover all the available CSS variables.

The <media-time-range> will be updated with media UI attributes any time your media playback state changes. You can use these attributes to apply custom styles to your <media-time-range> element under different state conditions.

/* Make the background color yellow when paused */
media-time-range[mediapaused] {
  --media-control-background: yellow;
}

/* Make the background color red when loading (buffering) */
media-time-range[medialoading] {
  --media-control-background: red;
}

Discover all the available media UI attributes.

NameDescription
previewAn element that slides along the timeline to the position of the pointer hovering.
currentAn element that slides along the timeline to the position of the current time.
NameTypeDescription
disabledbooleanThe Boolean disabled attribute makes the element not mutable or focusable.
aria-disabled
mediacontrollerstringThe element `id` of the media controller to connect to (if not nested within).

The media UI attributes will be set automatically by the controller if they are connected via nesting or the mediacontroller attribute. Only set these attributes manually if you know what you're doing.

NameTypeDescription
mediabufferedstring Set to the buffered time ranges.
mediaplaybackratestring Set to the media playback rate.
mediadurationstring Set to the media duration.
mediaseekablestring Set to the seekable time ranges.
mediapausedboolean Present if the media is paused.
medialoadingboolean Present if the media is loading.
mediacurrenttimestring Set to the current media time.
mediapreviewimagestring Set to the timeline preview image URL.
mediapreviewtimestring Set to the timeline preview time.
NameDescription
boxA CSS part that selects both the preview and current box elements.
preview-boxA CSS part that selects the preview box element.
current-boxA CSS part that selects the current box element.
NameDefaultDescription
--media-time-range-displayinline-blockdisplay property of range.
--media-preview-transition-propertyvisibility, opacitytransition-property of range hover preview.
--media-preview-transition-duration-out.25stransition-duration out of range hover preview.
--media-preview-transition-delay-out0stransition-delay out of range hover preview.
--media-preview-transition-duration-in.5stransition-duration in of range hover preview.
--media-preview-transition-delay-in.25stransition-delay in of range hover preview.
--media-preview-thumbnail-backgroundvar(--media-preview-background, var(--media-control-background, var(--media-secondary-color, rgb(20 20 30 / .7))))background of range preview thumbnail.
--media-preview-thumbnail-box-shadow0 0 4px rgb(0 0 0 / .2)box-shadow of range preview thumbnail.
--media-preview-thumbnail-max-width180pxmax-width of range preview thumbnail.
--media-preview-thumbnail-max-height160pxmax-height of range preview thumbnail.
--media-preview-thumbnail-min-width120pxmin-width of range preview thumbnail.
--media-preview-thumbnail-min-height80pxmin-height of range preview thumbnail.
--media-preview-thumbnail-border-radiusvar(--media-preview-border-radius) var(--media-preview-border-radius) 0 0border-radius of range preview thumbnail.
--media-preview-thumbnail-borderborder of range preview thumbnail.
--media-preview-time-backgroundvar(--media-preview-background, var(--media-control-background, var(--media-secondary-color, rgb(20 20 30 / .7))))background of range preview time display.
--media-preview-time-border-radius0 0 var(--media-preview-border-radius) var(--media-preview-border-radius)border-radius of range preview time display.
--media-preview-time-padding1px 10px 0padding of range preview time display.
--media-preview-time-margin0 0 10pxmargin of range preview time display.
--media-preview-time-text-shadow0 0 4px rgb(0 0 0 / .75)text-shadow of range preview time display.
--media-primary-colorrgb(238 238 238)Default color of range bar.
--media-secondary-colorrgb(20 20 30 / .7)Default color of range background.
--media-control-displayinline-blockdisplay property of control.
--media-control-padding10pxpadding of control.
--media-control-backgroundvar(--media-secondary-color, rgb(20 20 30 / .7))background of control.
--media-control-hover-backgroundrgb(50 50 70 / .7)background of control hover state.
--media-control-height24pxheight of control.
--media-range-paddingvar(--media-control-padding, 10px)padding of range.
--media-range-padding-leftvar(--_media-range-padding)padding-left of range.
--media-range-padding-rightvar(--_media-range-padding)padding-right of range.
--media-range-thumb-width10pxwidth of range thumb.
--media-range-thumb-height10pxheight of range thumb.
--media-range-thumb-bordernoneborder of range thumb.
--media-range-thumb-border-radius10pxborder-radius of range thumb.
--media-range-thumb-backgroundvar(--media-primary-color, rgb(238 238 238))background of range thumb.
--media-range-thumb-box-shadow1px 1px 1px transparentbox-shadow of range thumb.
--media-range-thumb-transitiontransition of range thumb.
--media-range-thumb-transformnonetransform of range thumb.
--media-range-thumb-opacity1opacity of range thumb.
--media-range-bar-colorvar(--media-primary-color, rgb(238 238 238))color_value of range bar (elapsed progress).
--media-range-track-colortransparentcolor_value of range track (remaining progress).
--media-range-track-backdrop-filterbackdrop-filter of range track.
--media-range-track-width100%width of range track.
--media-range-track-height4pxheight of range track.
--media-range-track-bordernoneborder of range track.
--media-range-track-outlineoutline of range track.
--media-range-track-outline-offsetoutline-offset of range track.
--media-range-track-border-radius1pxborder-radius of range track.
--media-range-track-box-shadownonebox-shadow of range track.
--media-range-track-transitiontransition of range track.
--media-range-track-translate-x0pxtranslate x-coordinate of range track.
--media-range-track-translate-y0pxtranslate y-coordinate of range track.
--media-range-track-backgroundrgb(255 255 255 / .2)background of range track background.
--media-range-track-background-backdrop-filterbackdrop-filter of range track background.
--media-time-range-hover-displayblockdisplay of range hover zone.
--media-time-range-hover-bottom-5pxbottom of range hover zone.
--media-time-range-hover-heightmax(100% + 5px, 20px)height of range hover zone.
--media-range-track-pointer-backgroundbackground of range track pointer.
--media-range-track-pointer-border-rightborder-right of range track pointer.