W3cubDocs

/DOM

HTMLMediaElement.autoplay

The HTMLMediaElement.autoplay property reflects the autoplay HTML attribute, indicating whether playback should automatically begin as soon as enough media is available to do so without interruption.

A media element whose source is a MediaStream and whose autoplay property is true will begin playback when it becomes active (that is, when MediaStream.active becomes true).

Sites which automatically play audio (or videos with an audio track) can be an unpleasant experience for users, so it should be avoided when possible. If you must offer autoplay functionality, you should make it opt-in (requiring a user to specifically enable it). However, this can be useful when creating media elements whose source will be set at a later time, under user control.

Syntax

HTMLMediaElement.autoplay = true | false;

var autoplay = HTMLMediaElement.autoplay;

Value

A Boolean whose value is true if the media element will begin playback as soon as enough content has loaded to allow it to do so without interruption.

Examples

...

<...></...>

...

Xxx.xxx()

Specifications

Browser compatibility

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes)[1] (Yes) 3.5 (1.9.1) [1] 9 ? ?
Feature Android Edge Firefox Mobile (Gecko) Firefox OS (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) (Yes) (Yes) ? (Yes) (Yes)

[1] Some versions of Chrome call this property autostart, rather than autoplay.

See also

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/autoplay