Some embedded videos on the web play automatically, how can I get my embedded video to play automatically?
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:
- Some browsers disable autoplay, in which case a user would have to change their settings to allow autoplay.
- If you decide to use the
autoplayattribute specifically with a video source that has an audio track, also consider adding the
mutedattribute for a better user experiece.