Our volunteers haven't translated this article into Türkçe yet. Join us and help get the job done!
You can also read the article in English (US).
The HTML <source> element specifies multiple media resources for the <picture>, the <audio> element, or the <video> element. It is an empty element, meaning that it has no content and does not have a closing tag. It is commonly used to serve the same media content in multiple formats supported by different browsers.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
| Content categories | None. |
|---|---|
| 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—
<audio> or <video>—and it must be placed before any flow content or <track> element. |
| Permitted ARIA roles | None |
| DOM interface | HTMLSourceElement |
Attributes
This element includes the global attributes.
sizes- Is a list of source sizes that describes the final rendered width of the image represented by the source. Each source size consists of a comma-separated list of media condition-length pairs. This information is used by the browser to determine, before laying the page out, which image defined in
srcsetto use.
Thesizesattribute has an effect only when the<source>element is the direct child of a<picture>element. src- Required for
<audio>and<video>, address of the media resource. The value of this attribute is ignored when the<source>element is placed inside a<picture>element. srcset- A list of one or more strings separated by commas indicating a set of possible images represented by the source for the browser to use. Each string is composed of:
- one URL to an image,
- a width descriptor, that is a positive integer directly followed by
'w'. The default value, if missing, is the infinity. - a pixel density descriptor, that is a positive floating number directly followed by
'x'. The default value, if missing, is1x.
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.
Thesrcsetattribute has an effect only when the<source>element is the direct child of a<picture>element. type- The MIME-type of the resource, optionally with a
codecsparameter. See RFC 4281 for information about how to specify codecs. media- Media query of the resource's intended media; this should be used only in a
<picture>element.
If the type attribute isn't specified, the media's type is retrieved from the server and checked to see if the user agent 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 the user agent can present, and if it's not recognized, the server doesn't even get queried; instead, the next <source> element is checked at once.
Usage notes
The <source> element is an empty element, which means that it not only has no content, but also has no closing tag. That is, you never use "</source>" in your HTML.
Examples
Video Example
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.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.
Picture Example
<picture> <source srcset="mdn-logo-wide.png" media="(min-width: 800px)"> <source srcset="mdn-logo-medium.png" media="(min-width: 600px)"> <img src="mdn-logo-narrow.png" alt="MDN"> </picture>
With the <picture> element, you must always include an <img> with a fallback image, with an alt attribute to ensure accessibility.
Specifications
| Specification | Status | Comment |
|---|---|---|
| HTML Living Standard The definition of '<source>' in that specification. |
Living Standard |
Browser compatibility
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
source | Chrome Full support Yes | Edge Full support Yes | Firefox
Full support
3.5
| IE Full support 9 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android
Full support
4
| Opera Android ? | Safari iOS Full support Yes | Samsung Internet Android Full support Yes |
media | Chrome Full support Yes | Edge Full support Yes | Firefox Full support 15 | IE Full support 9 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android Full support 15 | Opera Android ? | Safari iOS Full support Yes | Samsung Internet Android Full support Yes |
sizes | Chrome Full support Yes | Edge Full support Yes | Firefox
Full support
38
| IE ? | Opera Full support Yes | Safari
Full support
9
| WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android
Full support
38
| Opera Android ? | Safari iOS
Full support
9.2
| Samsung Internet Android Full support Yes |
src | Chrome Full support Yes | Edge Full support Yes | Firefox Full support 3.5 | IE Full support 9 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android Full support 4 | Opera Android ? | Safari iOS Full support Yes | Samsung Internet Android Full support Yes |
srcset | Chrome Full support Yes | Edge Full support Yes | Firefox
Full support
38
| IE ? | Opera Full support Yes | Safari
Full support
9
| WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android
Full support
38
| Opera Android ? | Safari iOS
Full support
9.2
| Samsung Internet Android Full support Yes |
type | Chrome Full support Yes | Edge Full support Yes | Firefox Full support 3.5 | IE Full support 9 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android Full support 4 | Opera Android ? | Safari iOS Full support Yes | Samsung Internet Android Full support Yes |
Legend
- Full support
- Full support
- Compatibility unknown
- Compatibility unknown
- See implementation notes.
- See implementation notes.
- User must explicitly enable this feature.
- User must explicitly enable this feature.
See also
<picture>element<audio>element<video>element- Web Performance

