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

Alex Hort-Francis
Alex Hort-Francis
17,074 Points

Is it strictly necessary to include the type attribute in a video or audio element?

As in (the example in the video): type="video/mp4"

Is this absolutely necessary, or considered best practice, or generally optional?

Having tested it myself in Workspaces, it seems video and audio content still loads without the attribute.

1 Answer

Steven Parker
Steven Parker
231,268 Points

MDN says: "If the MIME type for the video is not set correctly on the server, the video may not show or show a gray box containing an X". I suspect most browsers will also try to infer the type from the filename when not explicitly supplied, which would explain it working without it.