HTML <source > tag

HTML <source> tag is used as a child element to define more than one media resources for <audio>, <video>, and <picture> element.

It is used to provide the same media content with different formats such as mp3, mp4, etc.

When we embed multiple resources with the same content but different format then the browser may choose the most compatible format and display or play that media file.

The <source> tag was introduced in HTML5.

Syntax

Following are some specifications about the HTML <source> tag

DisplayInline
Start tag/End tagEmpty tag( Only start tag)
UsageMedia resource

Example

Test it Now

Output:

HTML source tag

Attribute:

Tag-specific attributes:

AttributeValueDescription
mediaMedia_queryIt determines that for which media/device the linked source is optimized.
sizesIt specifies acceptable image sizes for different page layout.
srcIt determines the URL of media files.
srcsetSpecifies the URL of the image for different situations. It is only used when <source> is child of <picture> element.
typevideo/ogg
video/mp4
video/webm
audio/ogg
audio/mpeg
It determines the media type of resource.

Global attribute:

The <source> tag supports the Global attributes in HTML.

Event attribute:

The <source> tag supports the Event attributes in HTML.

Supporting Browsers

Elementchrome browser Chromeie browser IEfirefox browser Firefoxopera browser Operasafari browser Safari
<source>YesYesYesYesYes
Next TopicHTML span Tag




Latest Courses