<source> element specifies multiple media resources for either the
<audio> or the
<video> element. It is an empty element. It is commonly used to serve the same media content in multiple formats supported by different browsers.
|Permitted content||None, it is an empty element.|
|Tag omission||It must have start tag, but must not have an end tag.|
|Permitted parents|| A media element— |
|Permitted ARIA roles||None|
|DOM interface|| |
This element includes the global attributes.
sizesattribute has an effect only when the
<source>element is the direct child of a
<video>, address of the media resource. The value of this attribute is ignored when the
<source>element is placed inside a
'w'. The default value, if missing, is the infinity.
'x'. The default value, if missing, is
Each string in the list must have at least a width descriptor or a pixel density descriptor to be valid. Among the list, there must be only one string containing the same tuple of width descriptor and pixel density descriptor.
The browser chooses the most adequate image to display at a given point of time.
srcset attribute has an effect only when the
<source> element is the direct child of a
codecsparameter. See RFC 4281 for information about how to specify codecs.
If the type attribute isn't specified, the media's type is retrieved from the server and checked to see if Gecko can handle it; if it can't be rendered, the next source is checked. If the type attribute is specified, it's compared against the types Gecko can play, and if it's not recognized, the server doesn't even get queried; instead, the next source element is checked at once.
This example demonstrates how to offer a video in Ogg format for users whose browsers support Ogg format, and a QuickTime format video for users whose browsers support that. If the
video element is not supported by the browser, a notice is displayed instead. If the browser supports the element but does not support any of the specified formats, an
error event is raised and the default media controls (if enabled) will indicate an error. See also the list of media formats supported by the audio and video elements in various browsers.
<video controls> <source src="foo.webm" type="video/webm"> <source src="foo.ogg" type="video/ogg"> <source src="foo.mov" type="video/quicktime"> I'm sorry; your browser doesn't support HTML5 video. </video>
For more examples, see Using audio and video in Firefox.
|WHATWG HTML Living Standard |
The definition of '<source>' in that specification.
|Feature||Chrome||Edge||Firefox (Gecko)||Internet Explorer||Opera||Safari|
|Basic support||(Yes)||(Yes)||3.5 (1.9.1)||9.0||(Yes)||(Yes)|
|Feature||Android||Edge||Firefox Mobile (Gecko)||IE Mobile||Opera Mobile||Safari Mobile|
|Basic support||(Yes)||(Yes)||1.0 (1.0)||?||?||?|
 This feature is behind the
dom.image.picture.enabled preference, defaulting to
Currently, only a small subset of the functionality is implemented — Gecko picks the first source element that has a type matching the MIME-type of a supported media format; see bug 449363 for details.
© 2005–2017 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.