The HTML <source>
tag is used to specify multiple media resources on media elements (such as <audio>
and <video>
).
This element allows you to specify alternative video and audio files which the browser may choose from based on its media type or codec support.
The <source>
tag was introduced in HTML 5.
In the example below, two files have been specified. The browser should choose which file (if any) it has support for.
<audio controls>
<source src="/music/good_enough.wma" type="audio/x-ms-wma">
<source src="/music/good_enough.mp3" type="audio/mpeg">
<p>If you are reading this, it is because your browser does not support the HTML 'audio' element.</p>
</audio>
The following table shows the attributes that are specific to this tag/element.
Attribute | Description |
---|---|
src | Specifies the location of the audio/video file. Its value must be the URL of an audio/video file. |
type | Specifies the type of the embedded content. If specified, the value must be a MIME type. |
media | Specifies the type of media resource, so the browser can determine whether it can play it or not. If not, it can choose not to download it. If specified, the value must be a valid media query. |