Definition
The autoplay attribute is a boolean that specifies whether the audio or video should begin to play automatically as soon as it starts to download. It does not wait for the whole file to be downloaded.
Applicable Elements
The autoplay Attribute can be used with the following elements:
HTML <video> autoplay Attribute
The <video> tag is used to embed a video player in your HTML document. It can contain multiple video sources, with the browser choosing the most suitable one.
The autoplay attribute is a boolean (either present on not) that specifies the video to begin automatically as soon as it can. It does not wait for the whole video file to be downloaded.
Syntax
<video src="video.mp4" autoplay muted></video>Usage
- The
autoplayattribute is a boolean attribute. - Most modern browsers do not allow autoplay on videos unless the video is also muted.
- To autoplay videos, you should also add both the
autoplayandmutedattributes. - If your video has no soundtrack, then it may play without the
mutedattribute.
Values
Values can include:
autoplay
Examples
A following example sets the video to autoplay while muted:
<video controls width="250" autoplay muted>
<source
src="https://file-examples-com.github.io/uploads/2020/03/file_example_WEBM_1920_3_7MB.webm"
type="video/webm"
/>
<source
src="https://res.cloudinary.com/thewebmaster/video/upload/v1614789951/image/file_example_WEBM_1920_3_7MB.mp4"
type="video/mp4"
/>
Sorry, your browser doesn't support embedded videos.
</video>HTML <audio> autoplay Attribute
The <audio> tag is used to embed a sound file in your HTML document. It can contain multiple audio sources, with the browser choosing the most suitable one via the <src> attribute or <source> element.
The autoplay attribute is a boolean attribute (either present on not) that specifies the audio to begin automatically as soon as it can. It does not wait for the whole audio file to be downloaded.
Syntax
<audio src="audiofile.ogg" autoplay></audio>Usage
- The
autoplayattribute is a boolean attribute. - Most modern browsers do not allow autoplay on audio unless the audio is also muted.
- To autoplay audio files, you should also add both the
autoplayandmutedattributes. This does make the use ofautoplaypretty much useless.
Values
Values can include:
autoplay
Examples
The following example sets the audio to autoplay while muted:
<figure style="margin: 0">
<figcaption>Listen to the Dog Bark:</figcaption>
<audio
controls
autoplay
muted
src="https://upload.wikimedia.org/wikipedia/commons/5/58/Barking_of_a_dog_2.ogg"
>
Your browser does not support the
<code>audio</code> element.
</audio>
</figure>Specification
The autoplay HTML specification for the <audio> and video elements is below:
Browser Support
The autoplay has the following browser support:
Desktop
| Chrome | Edge | Firefox | IE | Opera | Safari | |
|---|---|---|---|---|---|---|
<video> | Yes | Yes | Yes | Yes | Yes | Yes |
<audio> | Yes | Yes | Yes | Yes | Yes | Yes |
Mobile
| Android Webview | Chrome Android | Firefox Android | Opera Android | iOS Safari | Samsung Internet | |
|---|---|---|---|---|---|---|
<video> | Yes | Yes | Yes | Yes | Yes | Yes |
<audio> | Yes | Yes | Yes | Yes | Yes | Yes |
Most browsers only support autoplay when the audio or video is muted.
