HTML Media Sources: Formats and MIME Types
Provide alternate resources
Instead of a src on video, put source elements inside it. The browser evaluates candidates in order and can skip a type it does not support. The first usable candidate is generally chosen; it does not combine the files. These examples use the original files in media-fixtures/; open the supplied preview from a local static server or place the files at the shown paths.
<video controls width="160" height="90"> <source src="media-fixtures/demo.webm" type="video/webm"> <source src="media-fixtures/demo.mp4" type="video/mp4"></video>One supported clip is selected. The two files encode the same content.
Declare a MIME type
A MIME type identifies the resource format, for example audio/wav. A container holds encoded tracks; a codec defines the encoding of a track. A known container alone does not guarantee all its codecs are supported. The server must serve suitable resource headers.
<audio controls> <source src="media-fixtures/tone.wav" type="audio/wav"></audio>The type hints that the resource is WAV audio.
Separate fallback from source choice
Use either the parent src or child source candidates, not both. Child source elements are void elements. An ordinary link outside the player stays available even when every media candidate fails.
<video controls width="160" height="90"> <source src="media-fixtures/demo.mp4" type="video/mp4"> <source src="media-fixtures/demo.webm" type="video/webm"></video><p> <a href="media-fixtures/demo.webm">Open the video file</a></p>The first usable resource may differ across browsers; the link remains visible.
Common mistakes and practice
Do not use a filename extension as a guarantee of decoding support. Check the actual encoding and server MIME type. Try reversing the two sources.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
HTML Media Sources: Formats and MIME Types — Knowledge Check
Apply the media or embedding concepts from this lesson.
What is the purpose of the source type attribute?
How do multiple source children work?
Does video/mp4 guarantee decoding of every MP4?
A browser does not support the first listed source format. Why provide another source?
What should you check in addition to a media container's MIME type?