Summary -
In this topic, we described about the <source> tag along with detailed example.
The <source> tag was introduced in HTML 5. Alternative media resources on media elements. The <source> tag used to specify multiple alternative media.
Mostly media resources are video or audio. The browsers may choose the video files based on the media type and codec support as the tag allows to support alternative video/audio files.
The tag can be specified like <source src="" type=""> with media file link inserted between the double quotes of the src attribute. No end tag required as <source> tag is empty tag.
Syntax -
<source>.. text here.. </source>
Required Attributes -
Attribute | Description | Values |
---|---|---|
src | Specifies the source of the alternative media files | URL. |
Optional Attributes -
Attribute | Description | Values |
---|---|---|
Media | Specifies the type of the media resource | Media_query |
type | Specifies the type of the resource | text |
Example -
<!DOCTYPE html>
<html>
<head>
<title>source tag example.. </title>
</head>
<body>
<audio controls>
<source src="audio/new.mp3" type="audio/mpeg">
Browser does not support the audio element.
</audio>
</body>
</html>