You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
No way to read an image's true intrinsic dimensions when sizes="auto" (or any w-descriptor srcset) is used #12565
needs implementer interestMoving the issue forward requires implementers to express interesttopic: imgImages: img, picture, srcset and sizes, image loading and decoding, and image maps
No way to read an image's true intrinsic dimensions when sizes="auto" (or any w-descriptor srcset) is used
Summary
When an <img loading="lazy" sizes="auto"> uses a srcset with w descriptors, naturalWidth/naturalHeight always equal the element's layout/container width, not the resource's true intrinsic dimensions. Because naturalWidth returns the density-corrected natural width and the selected source's density is computed as descriptor / resolved-sizes, and sizes="auto" resolves sizes to the rendered width, the result is tautological: naturalWidth === containerWidth, for every image, regardless of the file's real pixel size.
This isn't a browser bug - it's the specified composition of two behaviors - but it leaves authors with no reliable API to recover an image's true intrinsic dimensions once w descriptors are involved, and sizes="auto" makes the gap unavoidable.
Reproduced in Chrome 149 (macOS). The math generalizes: a 400px container yields naturalWidth 400 (800w ÷ 400 = 2× density → 800/2 = 400).
Why this is a problem
Common use cases need the real intrinsic size — computing aspect ratio, deciding whether to upscale, lightbox/zoom logic, analytics on served resolution. With sizes="auto", all of these silently get the container size and break.
Possible directions
An accessor that exposes the un-corrected intrinsic dimensions of currentSrc (raw file pixels).
I think the fix is to expose the selected resource's dimensions directly. Reversing the density correction with the source size doesn't work anymore with #13046: naturalWidth is exactly the sizes value for images selected with a w descriptor.
Maybe pixelWidth/pixelHeight on both HTMLImageElement and HTMLVideoElement: the current resource's natural dimensions in image (or video) pixels. That's after orientation (and, for video, aspect-ratio correction), but before any density correction (from srcset or EXIF resolution). They'd be 0 if the image isn't available or has no natural dimensions.
naturalWidth and videoWidth would both stay the natural size in CSS pixels. For video that's the same as the pixel size today, since video has no density. If video gets srcset/sizes (#10379), videoWidth would become density-corrected like naturalWidth, and pixelWidth would mean the same thing on both elements.
Exposing the current source size (#6532) is also useful, for a different use case. Together, a sizes linter could check these without parsing sizes itself:
currentSizes vs clientWidth: is sizes accurate?
pixelWidth vs clientWidth × devicePixelRatio: is the served image too big or too small?
pixelWidth vs the selected candidate's w: is the w descriptor accurate?
I think the fix is to expose the selected resource's dimensions directly. Reversing the density correction with the source size doesn't work anymore with #13046: naturalWidth is exactly the sizes value for images selected with a w descriptor.
Maybe pixelWidth/pixelHeight on both HTMLImageElement and HTMLVideoElement: the current resource's natural dimensions in image (or video) pixels. That's after orientation (and, for video, aspect-ratio correction), but before any density correction (from srcset or EXIF resolution). They'd be 0 if the image isn't available or has no natural dimensions.
(bikeshedding) How about sourceWidth and sourceHeight?
Or selectedSource{Width|Height} and actualSource{Width|Height} if we want to be explicit about what was selected by the srcset algorithm and what actually arrived?
One thing I will note is that in Chrome Devtools, in the Elements tab, when hovering over an img element, the dialog popup includes the value that we desire and calls it intrinsic size.
This value is not density corrected but is the resources pixel width and height . Should we align on a name here to keep things consistent for developers?
(bikeshedding) How about sourceWidth and sourceHeight?
I'm OK with other names. But naturalWidth is also the selected source's width, so a name that says how this differs from naturalWidth and videoWidth seems better. How about resourceWidth?
Or selectedSource{Width|Height} and actualSource{Width|Height} if we want to be explicit about what was selected by the srcset algorithm and what actually arrived?
Exposing the selected w would allow checking whether the w descriptor is accurate. A currentDensity would, too (currentDensity × currentSizes vs resourceWidth, with currentSizes from #6532), and it also works for x descriptors.
@austinh In CSS, "intrinsic size" means something else now (sizing based on content). Before that, "intrinsic dimensions" was the old name for what CSS now calls "natural dimensions", which mostly matches naturalWidth. Either way, intrinsicWidth doesn't say how it differs from naturalWidth, and the two could be mistaken for synonyms.
10. @noamr
> (bikeshedding) How about sourceWidth and sourceHeight?
I'm OK with other names. But `naturalWidth` is also the selected source's width, so a name that says how this differs from `naturalWidth` and `videoWidth` seems better. How about `resourceWidth`?
How about object{Width|Height} as in object-fit?
But {image|video}{Width|Height} is also OK.
There are many "object"s, I don't think most people will think of object-fit first...
But {image|video}{Width|Height} is also OK.
This could work. Then imageWidth and videoWidth could be defined to be pretty similar, and if video gets srcset, we can add naturalWidth for the density-corrected CSS pixel width.
The spec says videoWidth is in CSS pixels, and allows format-defined scaling (resolution, MP4 tkhd presentation size), but browsers in practice report video pixels after aspect ratio correction (#13106). I think it should be defined that way, so it stays uncorrected if video gets srcset.
Per local testing with Claude: Firefox, Chrome and Safari don't apply the container-declared size (MP4 tkhd, WebM DisplayWidth/DisplayHeight) other than for aspect ratio, once the first frame is decoded (except AV1 in MP4 in Firefox, which looks like a bug (edit: filed bug 2084400)).
Sounds good. Anyway, hopefully there will be consensus on the utility of the feature and we can finish the bikeshed :)
Regarding pre/post orientation - we have to make sure we don't expose orientation etc for no-cors images/video.
So probably the dimensions in this case should be "what the rendered dimensions would be for a plain image/video with the selected source as the src and no other attributes/css", but perhaps I am missing something.
I just thought of something, we will likely also need to consider some equivalent "hard pixel" or "actual pixel" properties to naturalWidth/naturalHeight on PerformanceElementTiming
Chromium currently has a bug I believe and ships the intrinsic pixel size (we thought about taking advantage of this bug). core/paint/timing/element_timing.cc passes cached_image.IntrinsicSize(orientation), which is Image::Size, straight into the entry. No density anywhere. That is a spec deviation; it survived since 2019 because nobody tested srcset. Worth filing on w3c/element-timing so the raw value gets specced before someone “fixes” it.
needs implementer interestMoving the issue forward requires implementers to express interesttopic: imgImages: img, picture, srcset and sizes, image loading and decoding, and image maps
Activity
noamr commentedon Oct 6, 2026
cc @zcorpan
noamr commentedon Oct 12, 2026
I believe #13046 is also related.
zcorpan commentedon Oct 14, 2026
I think the fix is to expose the selected resource's dimensions directly. Reversing the density correction with the source size doesn't work anymore with #13046:
naturalWidthis exactly thesizesvalue for images selected with awdescriptor.Maybe
pixelWidth/pixelHeighton bothHTMLImageElementandHTMLVideoElement: the current resource's natural dimensions in image (or video) pixels. That's after orientation (and, for video, aspect-ratio correction), but before any density correction (fromsrcsetor EXIF resolution). They'd be 0 if the image isn't available or has no natural dimensions.naturalWidthandvideoWidthwould both stay the natural size in CSS pixels. For video that's the same as the pixel size today, since video has no density. If video getssrcset/sizes(#10379),videoWidthwould become density-corrected likenaturalWidth, andpixelWidthwould mean the same thing on both elements.Exposing the current source size (#6532) is also useful, for a different use case. Together, a
sizeslinter could check these without parsingsizesitself:currentSizesvsclientWidth: issizesaccurate?pixelWidthvsclientWidth × devicePixelRatio: is the served image too big or too small?pixelWidthvs the selected candidate'sw: is thewdescriptor accurate?noamr commentedon Oct 14, 2026
(bikeshedding) How about
sourceWidthandsourceHeight?Or
selectedSource{Width|Height}andactualSource{Width|Height}if we want to be explicit about what was selected by the srcset algorithm and what actually arrived?Otherwise this seems fine to me.
austinh commentedon Oct 14, 2026
Exposing a new property sounds good to me.
One thing I will note is that in Chrome Devtools, in the Elements tab, when hovering over an img element, the dialog popup includes the value that we desire and calls it intrinsic size.
Screenshot attached
See this article here: https://www.debugbear.com/docs/intrinsic-vs-rendered-size
This value is not density corrected but is the resources pixel width and height . Should we align on a name here to keep things consistent for developers?
intrinsicWidth|Height
zcorpan commentedon Oct 14, 2026
@noamr
I'm OK with other names. But
naturalWidthis also the selected source's width, so a name that says how this differs fromnaturalWidthandvideoWidthseems better. How aboutresourceWidth?Exposing the selected
wwould allow checking whether thewdescriptor is accurate. AcurrentDensitywould, too (currentDensity × currentSizesvsresourceWidth, withcurrentSizesfrom #6532), and it also works forxdescriptors.@austinh In CSS, "intrinsic size" means something else now (sizing based on content). Before that, "intrinsic dimensions" was the old name for what CSS now calls "natural dimensions", which mostly matches
naturalWidth. Either way,intrinsicWidthdoesn't say how it differs fromnaturalWidth, and the two could be mistaken for synonyms.noamr commentedon Oct 15, 2026
How about
object{Width|Height}as inobject-fit?But
{image|video}{Width|Height}is also OK.austinh commentedon Oct 19, 2026
actualSource{Width|Height}seems very clear to me and doesn't get confused with any existing properties or concepts fwiw.zcorpan commentedon Oct 20, 2026
There are many "object"s, I don't think most people will think of
object-fitfirst...This could work. Then
imageWidthandvideoWidthcould be defined to be pretty similar, and ifvideogetssrcset, we can addnaturalWidthfor the density-corrected CSS pixel width.The spec says
videoWidthis in CSS pixels, and allows format-defined scaling (resolution, MP4tkhdpresentation size), but browsers in practice report video pixels after aspect ratio correction (#13106). I think it should be defined that way, so it stays uncorrected if video getssrcset.Per local testing with Claude: Firefox, Chrome and Safari don't apply the container-declared size (MP4 tkhd, WebM DisplayWidth/DisplayHeight) other than for aspect ratio, once the first frame is decoded (except AV1 in MP4 in Firefox, which looks like a bug (edit: filed bug 2084400)).
noamr commentedon Oct 21, 2026
Sounds good. Anyway, hopefully there will be consensus on the utility of the feature and we can finish the bikeshed :)
Regarding pre/post orientation - we have to make sure we don't expose orientation etc for no-cors images/video.
So probably the dimensions in this case should be "what the rendered dimensions would be for a plain image/video with the selected source as the src and no other attributes/css", but perhaps I am missing something.
austinh commentedon Oct 21, 2026
I just thought of something, we will likely also need to consider some equivalent "hard pixel" or "actual pixel" properties to
naturalWidth/naturalHeightonPerformanceElementTimingChromium currently has a bug I believe and ships the intrinsic pixel size (we thought about taking advantage of this bug). core/paint/timing/element_timing.cc passes cached_image.IntrinsicSize(orientation), which is Image::Size, straight into the entry. No density anywhere. That is a spec deviation; it survived since 2019 because nobody tested srcset. Worth filing on w3c/element-timing so the raw value gets specced before someone “fixes” it.