s ource Redirect 1

Summary

The source element is used to specify multiple media resources for audio and video elements in HTML5. It is an empty element. It is commonly used to serve the same media in multiple formats supported by different browsers.

Usage Context

Permitted content None; this is a void element.
Tag omission Must have a start tag, and must not have an end tag.
Permitted parent elements <audio>, <video>
Normative document HTML5, section 4.8.8

Attributes

This element includes the global attributes.

src
Required, address of the media resource.
type
The MIME-type of the resource, optionally with a codecs parameter. See RFC 4281 for information about how to specify codecs.
media
Media query of the resource's intended media.

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.

DOM Interface

This element implements the HTMLSourceElement interface.

Examples

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 audio or 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.ogg" type="video/ogg"> <!-- Picked by Firefox -->
  <source src="foo.mov" type="video/quicktime"> <!-- Picked by Safari -->
  I'm sorry; your browser doesn't support HTML5 video.
</video>

For more examples, see Using audio and video in Firefox.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) 3.5 (1.9.1) 9.0 (Yes) (Yes)
media attribute (Yes) 15.0 (15.0) 9.0 (Yes) (Yes)
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) 1.0 (1.0) ? ? ?
media attribute (Yes) 15.0 (15.0) ? ? ?

Gecko-specific notes

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.

Document Tags and Contributors

Contributors to this page: Sheppy
Last updated by: Sheppy,