Skip to content

GuidePlayback

Autoplay

Start playback automatically and handle browser autoplay restrictions.

For the best chance of autoplay succeeding, start playback muted and enable inline playback. Autoplay is a request, not a guarantee: browsers can block it based on audio state, prior interaction with your site, browser settings, and platform policy.

Set autoplay, muted, and inline playback on the media component, and keep a manual play control available for when autoplay is blocked.

Play Pause Replay
<video-player class="video-player">
  <media-container>
    <video src="https://stream.mux.com/BV3YZtogl89mg9VcNBhhnHm02Y34zI1nlMuMQfAbl3dM/highest.mp4" autoplay muted playsinline></video>
    <media-play-button class="media-play-button">
      <span class="paused">Play</span>
      <span class="playing">Pause</span>
      <span class="ended">Replay</span>
    </media-play-button>
  </media-container>
</video-player>

How it works

The autoplay, muted, and playsinline attributes on <video> and similar media components pass through to the underlying media element. The media element applies the attributes it supports and requests playback as soon as it has enough data.

The playback feature reflects the result in player state. When autoplay succeeds, paused becomes false and started becomes true. When the browser blocks autoplay, the player stays paused: true with started: false, and the Play button renders its play state. There is no separate autoplay failure event: a blocked autoplay looks like media that never started.

Calling play() from player state returns the native promise from the media element. When the browser blocks playback, that promise rejects with a NotAllowedError.

Availability and constraints

  • Autoplay can fail. Browsers decide per page load based on audio state, whether the user has interacted with your site before, browser settings, and platform policy.
  • Muted autoplay is broadly allowed. Unmuted autoplay is blocked on first visit in most browsers; do not rely on it.
  • Without inline playback, iPhone Safari opens the video in fullscreen when playback starts.
  • Low-power mode and data-saver settings can block even muted autoplay. This is why the recommended approach keeps a manual play control.
  • Programmatic volume control is unsupported on some platforms. The volume feature reports support through volumeAvailability. It starts as 'unavailable' before media attachment. On iOS Safari, it reports 'unsupported'.
  • This guide applies to media components that render a video element (<video>, <hlsjs-video>, <dash-video>, <mux-video>, and the like). Embed components (YouTube, Vimeo, TikTok, Twitch) forward autoplay to the third-party player, which applies its own autoplay rules; muted and inline behavior varies by provider.

Common variations

Background video

Use <background-video> for an MP4 or WebM file, <hls-background-video> for an HLS stream, or <mux-background-video> for a complete Mux HLS URL.

These components default to muted, looping playback without player controls. Provide a separate motion control and respect reduced-motion preferences. For setup and motion controls, follow Add a background video. That guide also covers streaming backgrounds, which always autoplay and need conditional mounting.

Autoplay with sound

Do not rely on unmuted autoplay for a user’s first visit. Start playback from an explicit user action instead.

Call play() on the media component from a click handler:

<video-player>
  <media-container>
    <video src="https://stream.mux.com/BV3YZtogl89mg9VcNBhhnHm02Y34zI1nlMuMQfAbl3dM/highest.mp4" playsinline></video>
  </media-container>
</video-player>
<button type="button" id="start">Play video</button>
<script type="module">
  import '@videojs/html/video/player';
  import '@videojs/html/ui/container';

  document.querySelector('#start').addEventListener('click', () => {
    document.querySelector('video').play().catch(console.error);
  });
</script>

Calling play() directly from the click handler lets the browser authorize unmuted playback. The promise can still reject; these examples log the rejection and leave the button available to retry. For source and decoding failures, see Handle playback errors.

Troubleshooting

Playback does not start

Confirm that:

  • The media is muted.
  • Inline playback is enabled.
  • The source loads (check the network panel).
  • A manual play control is available as a fallback.

If autoplay is blocked, the player stays paused and the Play button remains in its play state; there is no error state to handle.

The video opens fullscreen on iPhone

Enable inline playback with the playsinline attribute on the media component.

The video starts without sound

Expected with muted autoplay. Give the user a Mute button to unmute through an explicit action. Unmuting without a user action can cause the browser to pause or block playback. A Volume slider can also unmute where volume control is supported; it hides on platforms such as iOS Safari.

Components

API

Guides