Using the autoplay attribute
The autoplay
attribute starts the audio or video file once the browser has loaded the page. It follows the src
attribute and can go in tandem with the muted
attribute. If you decide to use autoplay
, it's crucial to include controls to prevent an unpleasant surprise for users.
Keep in mind that many browsers block autoplay media if:
• Its volume isn't on mute or silenced to 0
• Users haven't interacted with the site in any way yet (by clicking, tapping, or pressing keys)
• Your website isn't on a white list
Sometimes, users manually define the white list, or browsers automatically add your website if users engage with media frequently.