The height property of the HTMLSourceElement interface is a non-negative number indicating the height of the image resource in CSS pixels.
The property has an effect only if the parent of the current <source> element is a <picture> element.
It reflects the height attribute of the <source> element.
A non-negative number indicating the height of the image resource in CSS pixels.
<picture id="img">
<source
srcset="landscape.png"
media="(width >= 1000px)"
width="1000"
height="400" />
<source
srcset="square.png"
media="(width >= 800px)"
width="800"
height="800" />
<source
srcset="portrait.png"
media="(width >= 600px)"
width="600"
height="800" />
<img
src="fallback.png"
alt="Image used when the browser does not support the sources"
width="500"
height="400" />
</picture>
const img = document.getElementById("img");
const sources = img.querySelectorAll("source");
console.log(Array.from(sources).map((el) => el.height)); // Output: [400, 800, 800]
| Specification |
|---|
| HTML> # dom-dim-height> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
height |
90 | 90 | 108 | 76 | 15 | 90 | 108 | 64 | 15 | 15.0 | 90 | 15 |
HTMLCanvasElement.heightHTMLEmbedElement.heightHTMLIFrameElement.heightHTMLImageElement.heightHTMLObjectElement.heightHTMLVideoElement.height
© 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/height