Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML HTML Video and Audio Media Basics The Video Element

autoplay not working

<video src="http://treehouse-code-samples.s3.amazonaws.com/html-video-and-audio/bridge.mp4" type="video/mp4"/>

The autoplay is not working upon page load

For Chrome 70.0 and up (and maybe some other browsers)

autoplay doesn't work if no muted attribute is present

according to MDN.

I added muted as a boolean attribute (no value attached, like when adding controls or autoplay) and it now works.

<video src="http://treehouse-code-samples.s3.amazonaws.com/html-video-and-audio/bridge.mp4" type="video/mp4" autoplay muted />

muted did the trick, but can I ask how you figured that out ? did you just search "autoplay attribute not working"? or... ,I am very green to coding and interested in learning how to learn , as well as learning code.

1 Answer

Alexandra Hadjidaki
Alexandra Hadjidaki
26,496 Points

If you want your video to autoplay on page load, you need to let it know you want to do that

Add the autoplay attribute to your video tag like so:

<video src="http://treehouse-code-samples.s3.amazonaws.com/html-video-and-audio/bridge.mp4" type="video/mp4" autoplay/>


Suggestion

A better way to add video to your HTML would be the following, in case the browser doesn't support the video embed element:

<video autoplay>
    <source src="http://treehouse-code-samples.s3.amazonaws.com/html-video-and-audio/bridge.mp4" 
            type="video/mp4">
    <!-- You can add more source types here -->
    Sorry, your browser doesn't support embedded videos.
</video>

MDN Documentation for <video> element