Dofactory.com
Dofactory.com
Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.

HTML autoplay Attribute

The autoplay attribute on a media player specifies that the element immediately starts playing the media file once the page is loaded.

Elements that accept this attribute are <audio>, and <video>.

Example

#

An autoplay attribute on an <audio> element. 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

With this attribute, the audio or video file will start playing even before the entire file is loaded.

Suddenly playing an audio or video may startle users because they are not expecting it.

It is usually best to give users control over when to start.


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




Last updated on Sep 30, 2023

Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.

Guides