The HTMLSourceElement interface provides special properties (beyond the regular HTMLElement object interface it also has available to it by inheritance) for manipulating <source> elements.
Inherits properties from its parent, HTMLElement.
HTMLSourceElement.heightA number that reflects the height HTML attribute, indicating the height of the image resource in CSS pixels. The property has a meaning only if the parent of the current <source> element is a <picture> element.
HTMLSourceElement.mediaA string reflecting the media HTML attribute, containing the intended type of the media resource.
HTMLSourceElement.sizesA string representing image sizes between breakpoints
HTMLSourceElement.srcA string reflecting the src HTML attribute, containing the URL for the media resource. The HTMLSourceElement.src property has a meaning only when the associated <source> element is nested in a media element that is a <video> or an <audio> element. It has no meaning and is ignored when it is nested in a <picture> element.
Note: If the src property is updated (along with any siblings), the parent HTMLMediaElement's load method should be called when done, since <source> elements are not re-scanned automatically.
HTMLSourceElement.srcsetA string reflecting the srcset HTML attribute, containing a list of candidate images, separated by a comma (',', U+002C COMMA). A candidate image is a URL followed by a 'w' with the width of the images, or an 'x' followed by the pixel density.
HTMLSourceElement.typeA string reflecting the type HTML attribute, containing the type of the media resource.
HTMLSourceElement.widthA number that reflects the width HTML attribute, indicating the width of the image resource in CSS pixels. The property has a meaning only if the parent of the current <source> element is a <picture> element.
No specific method; inherits methods from its parent, HTMLElement.
| Specification |
|---|
| HTML> # htmlsourceelement> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
HTMLSourceElement |
3 | 12 | 3.5 | ≤12.1 | 3.1 | 18 | 4 | ≤12.1 | 2 | 1.0 | 4.4 | 2 |
height |
90 | 90 | 108 | 76 | 15 | 90 | 108 | 64 | 15 | 15.0 | 90 | 15 |
media |
3 | 12 | 15 | ≤12.1 | 3.1 | 18 | 15 | ≤12.1 | 2 | 1.0 | 4.4 | 2 |
sizes |
38 | 13 | 38 | 25 | 10.1Thesizes attribute is supported since Safari 9.1. |
38 | 38 | 25 | 10.3Thesizes attribute is supported since Safari on iOS 9.1. |
3.0 | 38 | 10.3Thesizes attribute is supported since WebView on iOS 9.1. |
src |
3 | 12 | 3.5 | ≤12.1 | 3.1 | 18 | 4 | ≤12.1 | 2 | 1.0 | 4.4 | 2 |
srcset |
38 | 13 | 38 | 25 | 10.1Thesrcset attribute is supported since Safari 9.1. |
38 | 38 | 25 | 10.3Thesrcset attribute is supported since Safari on iOS 9.1. |
3.0 | 38 | 10.3Thesrcset attribute is supported since WebView on iOS 9.1. |
type |
3 | 12 | 3.5 | ≤12.1 | 3.1 | 18 | 4 | ≤12.1 | 2 | 1.0 | 4.4 | 2 |
width |
90 | 90 | 108 | 76 | 15 | 90 | 108 | 64 | 15 | 15.0 | 90 | 15 |
<source>.<source> element: HTMLVideoElement, HTMLAudioElement, HTMLPictureElement.
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLSourceElement