HTMLMediaElement: autoplay property
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
TheHTMLMediaElement.autoplayproperty reflects theautoplay HTML attribute, indicatingwhether playback should automatically begin as soon as enough media is available to doso without interruption.
A media element whose source is aMediaStream and whoseautoplay property istrue will begin playback when it becomesactive (that is, whenMediaStream.active becomestrue).
Note:Sites which automatically play audio (or videos with an audiotrack) can be an unpleasant experience for users, so it should be avoided whenpossible. If you must offer autoplay functionality, you should make it opt-in(requiring a user to specifically enable it). However, autoplay can be useful whencreating media elements whose source will be set at a later time, under user control.
For a much more in-depth look at autoplay, autoplay blocking, and how to respond whenautoplay is blocked by the user's browser, see our articleAutoplay guide for media and Web Audio APIs.
In this article
Value
A boolean value which istrue if the media element willbegin playback as soon as enough content has loaded to allow it to do so withoutinterruption.
Note:Some browsers offer users the ability to overrideautoplay in order to prevent disruptive audio or video from playingwithout permission or in the background. Do not rely onautoplay actuallystarting playback and instead useplayevent.
Examples
<video controls> <source src="https://player.vimeo.com/external/250688977.sd.mp4?s=d14b1f1a971dde13c79d6e436b88a6a928dfe26b&profile_id=165" /></video>// Disable autoplay (recommended)// false is the default valuedocument.querySelector("#video").autoplay = false;Specifications
| Specification |
|---|
| HTML> # dom-media-autoplay> |
Browser compatibility
See also
HTMLMediaElement: Interface used to define theHTMLMediaElement.autoplayproperty<audio>,<video>