Skip to content

Responsive images with srcset unexpectedly upscale when using object-fit: none or scale-down #11428

Open

Description

@zipper

What is the issue with the HTML Standard?

Summary

When using <img> with a srcset containing width (w) descriptors — especially without a sizes attribute, or with a sizes value larger than the physical image — browsers compute a density-corrected intrinsic size that may exceed the image's actual pixel dimensions.

This value is then used as the image’s rendered size even when object-fit: none or object-fit: scale-down is set, which leads to the image being upscaled. This feels wrong to me, because one would expect these object-fit values to prevent upscaling and display the image at its natural size.

Comparison with plain src and srcset with x descriptors

If I omit srcset and use only a plain src, no upscaling occurs — even if the image is placed in a larger container. This is intuitive and expected: the image is displayed at its natural resolution, and object-fit: none respects that.

When I use srcset with x descriptors (like 1x, 2x), the behavior is also intuitive: no upscaling occurs under object-fit: none or scale-down.

However, with w descriptors (especially with missing or overly large sizes), the browser computes a larger density-corrected intrinsic size and renders the image larger than its pixel resolution — even with object-fit: none or scale-down.

Browser behavior

Current browser behavior:

  • Chrome (as of recent versions) prevents upscaling with object-fit: scale-down. It uses the smaller of the container size and the image’s intrinsic pixel dimensions. This aligns with developer expectations, but is technically not compliant with the current spec.
  • Firefox and Safari follow the spec more strictly and upscale the image to the density-corrected intrinsic size even when object-fit: none or scale-down is set.

Why this seems problematic

  • Inconsistent: Adding a srcset with no new information (or switching from x to w) changes rendering in unintuitive ways.
  • Unexpected: object-fit: none or scale-down should, in my opinion, prevent upscaling.
  • Hard to control: Developers must manually manipulate sizes or avoid srcset altogether to avoid unintentional upscaling.

My interpretation of sizes and object-fit

I believe the sizes attribute is meant to represent the available layout space an image will occupy — similar to how CSS width works. The acutal image dimensions are represented by the w descriptor. Therefore, I would expect object-fit to be allowed to constrain or override the density-corrected intrinsic size.

When a developer explicitly requests object-fit: none or scale-down, they are expressing intent not to upscale the image — and that intent should not be overridden by image selection heuristics.

This is especially noticeable with sizes="auto", which effectively means “use whatever size is determined by CSS”. In that sense, it behaves similarly to using only src with layout-driven dimensions — yet with srcset and w descriptors, the image may still be upscaled, breaking the expectation of consistent rendering based on layout alone.

Proposal

Please consider adjusting the specification so that:

  • When object-fit is none or scale-down, the image’s rendered size should be clamped to its physical pixel dimensions (or the smaller of intrinsic and natural sizes in the case of scale-down).
  • The density-corrected intrinsic size should still be computed as usual, but object-fit must be allowed to constrain the final display size.

This would bring consistent behavior across:

  • Static images (src)
  • Responsive images (srcset with x or w)
  • All relevant object-fit values

Demo

Here’s a CodePen that illustrates the issue:
🔗 https://codepen.io/zipper/pen/gvJBdp
First image in each group represents the src only image, second is with srcset, third the same but in a narrow container and the last one uses an x descriptor. Note that the images using x descriptors behave as expected — they do not upscale, which highlights the inconsistency.

Related issues

Activity

  1. Ahmad-S792 commented on Jul 7, 2025

    @Ahmad-S792

    NOTE - from Safari / WebKit side, it was fixed but backed out.

  2. eeeps commented on Oct 13, 2026

    @eeeps
    Contributor

    Possibly relevant resolved issues from a couple of years ago: w3c/csswg-drafts#10116 and #10079

  3. eeeps commented on Oct 13, 2026

    @eeeps
    Contributor

    IIUC, this would require adding a new primitive in addition to the existing natural dimensions, density-corrected intrinsic dimensions, concrete size, and default size -- "actual asset dimensions" or something -- and integrating it into the object-fit spec.

    I know the fact that actual asset dimensions are easy to reliably infer cross-origin is considered a hole in the same-origin policy. Would adding this primitive and exposing it in how images are rendered (if not sized for layout) make that hole worse in any way?

  4. noamr commented on Oct 21, 2026

    @noamr
    Contributor

    I think this is the same as what we are proposing for #12248

  5. added
    topic: img
    on Nov 18, 2026
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

    topic: img

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions