HTML autoplay Attribute

The autoplay attribute on a media player specifies that the element immediately starts playing the media file when the page is loaded. Elements that accept this attribute include <audio>, and <video>.

Example

#

An autoplay attribute on an <audio> element.
Note: to avoid surprises, we disabled autoplay on this page. Click 'Try It live' to see it enabled.

<audio autoplay controls>
  <source src="/media/epic.mp3" type="audio/mpeg">
  <source src="/media/epic.wav" type="audio/wav">
</audio>

For additional details see our HTML audio autoplay Reference.


Using autoplay

The autoplay attribute specifies that the media player starts when the page is loaded.

With this attribute, the media file will start playing even before the entire file is loaded.

Tip: Automatically playing audio or video may surprise users because they are not expecting it.
It is better to give the users full control over when to start the audio or video.


Syntax

<tagname autoplay>

Elements accepting autoplay

These elements accept the autoplay attribute:

Elements Description
<audio> Creates an audio player -- see example above
<video> Creates a video player

<video> with autoplay

An autoplay attribute on a <video> tag.
Note: we disabled autoplay on this page. Click 'Try It live' to see it enabled.

<video width="320" autoplay>
  <source src="/media/movie.mp4" type="video/mp4">
  <source src="/media/movie.ogg" type="video/ogg">
</video>

For additional details see our HTML video autoplay Reference.


Browser support

Here is when autoplay support started for each browser:

Chrome
1.0 Sep 2008
Firefox
1.0 Sep 2002
IE/Edge
1.0 Aug 1995
Opera
1.0 Jan 2006
Safari
1.0 Jan 2003

You may also like



Guides