source
Definition and Usage
The <source> tag is used to specify multiple media resources for media elements such as <video>, <audio> and <picture>. The <source> tag allows you to specify alternative video/audio/image files which the browser may choose from, based on its media type, codec support or media query.It is an empty element. It is commonly used to serve the same media content in multiple formats supported by different browsers. The tag was introduced in HTML 5.Syntax
The<source>
tag is written as <source src="" type="">
(no end tag) with the URL of the media listed between the double quotes of the src
attribute. The type
attribute can be used to specify the type of the media resource. This helps the browser determine whether or not it can play the media resource before downloading it.
Attributes
Attribute | Value | Description |
---|---|---|
src | URL | Required when <source> is used in <audio> and <video>. Specifies the URL of the media file. Syntax:<source src="URL"> |
srcset | URL | Required when <source> is used in <picture>. Specifies the URL of the image to use in different situations. Syntax:<source srcset="URL"> |
media | media_query | Accepts any valid media query that would normally be defined in a CSS Syntax:<source media="media_query"> |
sizes | Specifies image sizes for different page layouts | |
type | MIME-type | Specifies the MIME-type of the resource |