Repository navigation
Description
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: noneorscale-downis set.
Why this seems problematic
- Inconsistent: Adding a
srcsetwith no new information (or switching fromxtow) changes rendering in unintuitive ways. - Unexpected:
object-fit: noneorscale-downshould, in my opinion, prevent upscaling. - Hard to control: Developers must manually manipulate
sizesor avoidsrcsetaltogether 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-fitisnoneorscale-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 ofscale-down). - The density-corrected intrinsic size should still be computed as usual, but
object-fitmust be allowed to constrain the final display size.
This would bring consistent behavior across:
- Static images (
src) - Responsive images (
srcsetwithxorw) - All relevant
object-fitvalues
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
- Firefox (closed as invalid) https://bugzilla.mozilla.org/show_bug.cgi?id=1974747
- Chrome (
xdescriptor, fixed) https://issues.chromium.org/issues/40648128 - Chrome (
wdescriptor, "fixed", but not compliant with the spec) https://issues.chromium.org/issues/41374573 - Safari (
wdescriptor, "fixed", but not compliant with the spec) https://bugs.webkit.org/show_bug.cgi?id=295203
Activity
Ahmad-S792 commentedon Jul 7, 2025
NOTE - from Safari / WebKit side, it was fixed but backed out.
eeeps commentedon Oct 13, 2026
Possibly relevant resolved issues from a couple of years ago: w3c/csswg-drafts#10116 and #10079
eeeps commentedon Oct 13, 2026
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-fitspec.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?
noamr commentedon Oct 21, 2026
I think this is the same as what we are proposing for #12248