Skip to content

No way to read an image's true intrinsic dimensions when sizes="auto" (or any w-descriptor srcset) is used #12565

Open

Description

@austinh

What is the issue with the HTML Standard?

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.

Reproduction

JSFiddle: https://jsfiddle.net/ns58rcub/5/

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

  1. An accessor that exposes the un-corrected intrinsic dimensions of currentSrc (raw file pixels).
  2. Expose the resolved source size (cf. proposed currentSizes in Getting the current source size value of an img #6532) so authors can reverse the density correction themselves.
  3. At minimum, a spec note documenting that naturalWidth/naturalHeight are tautological under sizes="auto".

Related: #6532 (requesting access to the computed source size value) — same root cause.

Activity

  1. added
    needs implementer interest
    topic: img
    on Oct 6, 2026
  2. noamr commented on Oct 6, 2026

    @noamr
    Contributor
  3. noamr commented on Oct 12, 2026

    @noamr
    Contributor

    I believe #13046 is also related.

  4. zcorpan commented on Oct 14, 2026

    @zcorpan
    Member

    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?
  5. noamr commented on Oct 14, 2026

    @noamr
    Contributor

    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?

    Otherwise this seems fine to me.

  6. austinh commented on Oct 14, 2026

    @austinh
    Author

    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 image

    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

  7. zcorpan commented on Oct 14, 2026

    @zcorpan
    Member

    @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?

    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.

  8. noamr commented on Oct 15, 2026

    @noamr
    Contributor

    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.

  9. austinh commented on Oct 19, 2026

    @austinh
    Author

    actualSource{Width|Height} seems very clear to me and doesn't get confused with any existing properties or concepts fwiw.

  10. zcorpan commented on Oct 20, 2026

    @zcorpan
    Member

    How about object{Width|Height} as in object-fit?

    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)).

  11. noamr commented on Oct 21, 2026

    @noamr
    Contributor

    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.

  12. austinh commented on Oct 21, 2026

    @austinh
    Author

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs implementer interesttopic: img

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions