Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

HTML HTML Video and Audio Media Basics The Video Element

Alex Francis
Alex Francis
13,840 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
216,810 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.