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 -

AttributeDescriptionValues
srcSpecifies the source of the alternative media filesURL.

Optional Attributes -

AttributeDescriptionValues
MediaSpecifies the type of the media resourceMedia_query
typeSpecifies the type of the resourcetext

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>

Output -