HTML <source> Element
The <source> tag is used to specify multiple sources for media elements, such as <audio> and <video>. This allows the browser to choose the most appropriate source to use based on the user's device and browser capabilities.
Here is an example of how to use the <source> tag within a <video> element:
<video controls>
<source src="video.mp4" type="video/mp4">
<source src="audio.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>
In this example, the browser will first try to play the movie.mp4 file, and if it's not supported, it will fall back to the movie.ogg file.
<source> Tag Attributes
| Attribute |
Description |
| src |
Specifies the URL of the media file |
| type |
Specifies the media type of the source file |
Here is an example of using the <source> tag with the <audio> element:
<audio controls>
<source src="audio.mp3" type="audio/mpeg">
<source src="audio.ogg" type="audio/ogg">
Your browser does not support the audio tag.
</audio>
In this example, the browser will try to play the song.mp3 file first, and if it's not supported, it will play the song.ogg file.