Some videos on the web play automatically, how can I get my video to play automatically?


#1

Question

Some embedded videos on the web play automatically, how can I get my embedded video to play automatically?

Answer

To get a video element to play automatically on page load, we can add the autoplay attribute to the opening <video> tag, like this:

<video width="320" height="240" autoplay> 
  <source src="https://s3.amazonaws.com/codecademy-content/projects/make-a-website/lesson-1/ollie.mp4" type="video/mp4"> 
</video>

A couple things to note:

  1. Some browsers disable autoplay, in which case a user would have to change their settings to allow autoplay.
  2. If you decide to use the autoplay attribute specifically with a video source that has an audio track, also consider adding the muted attribute for a better user experiece.