Skip to content

Support 2D sizes and height descriptors in srcset - #13053

Open
noamr wants to merge 18 commits into
mainfrom
noamr/srcset-2d
Open

noamr wants to merge 18 commits into
mainfrom
noamr/srcset-2d

Conversation

@noamr

@noamr noamr commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

This allows responsive image selection to account for both dimensions and object fitting (contain / cover), fixing source selection when an image is constrained by height or object-fit.

  • Re-introduces the <height-descriptor> (<positive-integer>h) alongside <width-descriptor> (w) in srcset image candidate strings so each candidate's aspect ratio can be determined before fetching.
  • Extends <source-size-value> to accept [ contain | cover ] <length> <length>, representing a fit mode, width, and height. Bare 2D <source-size> items without a <media-condition> are permitted before the final item in a <source-size-list> without a parse error so authors can provide a 1D fallback for legacy user agents (e.g., sizes="cover 400px 400px, 400px").
  • Instead of using the concrete object size width (which depends on the already-loaded image's natural aspect ratio or causes inconsistent selection with object-fit: cover / contain), sizes="auto" now resolves to a source size struct using the img element's content box width and height and its computed 'object-fit' value ('contain'/'scale-down' -> "contain", 'cover' -> "cover", 'fill'/'none' -> "fill").
  • Computes each candidate's aspect ratio from its w and h descriptors (falling back to the dimension attribute aspect ratio from width/height attributes on the element, derives the candidate's source concrete width given the source size's width, height, and fit, and normalizes the candidate's pixel density using that concrete width prior to select an image source from a source set (covering <img>, <picture><source>, <link rel="preload" as="image">, and Link: HTTP preload headers).
  • Tracks width and height attribute mutations on <img> and preceding <source> elements in <picture>, and for sizes="auto", reacts to changes in the img's content box width or height or computed 'object-fit' property.

Fixes #12248.
Fixes #2973.


(This comment was updated by the HTML Standard PR Preview Bot.)


/embedded-content.html ( diff )
/images.html ( diff )
/infrastructure.html ( diff )
/semantics.html ( diff )

beckysiegel pushed a commit to chromium/chromium that referenced this pull request Oct 16, 2026
Implements the parsing parts of
whatwg/html#13053 behind the
`SrcsetTwoDimensionalSizes` runtime flag:

- Represent a resolved source size as a `TargetBoxSize` (`width`,
  optional `height`, and `object_fit`), and thread it through
  `SizesAttributeParser`, `HTMLImageElement::SourceSize()`, the preload
  scanner and `BestFitSource*`.
  One-dimensional sizes populate only `width`, so this is a no-op
  refactor for existing behavior.
- Parse the `<positive-integer>h` height descriptor in `srcset` when
  paired with a `w` descriptor, and compute each candidate's source
  concrete width from the `TargetBoxSize` and the candidate's aspect
  ratio when fitting with `contain` or `cover`.
- Parse the explicit `[contain | cover] <length> <length>` source size
  syntax in `sizes`.

Making `sizes="auto"` two-dimensional (using the box height and computed
`object-fit`), and using the `width`/`height` attributes as a default
aspect ratio for candidates without an `h` descriptor, are implemented
in follow-up CLs.

Bug: 572724710
Change-Id: I17fd93318d0955fbb3d6ce8aed7d085174671ddd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8559899
Reviewed-by: Stefan Zager <szager@chromium.org>
Commit-Queue: Noam Rosenthal <nrosenthal@google.com>
Cr-Commit-Position: refs/heads/main@{#1720204}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Oct 16, 2026
Implements the parsing parts of
whatwg/html#13053 behind the
`SrcsetTwoDimensionalSizes` runtime flag:

- Represent a resolved source size as a `TargetBoxSize` (`width`,
  optional `height`, and `object_fit`), and thread it through
  `SizesAttributeParser`, `HTMLImageElement::SourceSize()`, the preload
  scanner and `BestFitSource*`.
  One-dimensional sizes populate only `width`, so this is a no-op
  refactor for existing behavior.
- Parse the `<positive-integer>h` height descriptor in `srcset` when
  paired with a `w` descriptor, and compute each candidate's source
  concrete width from the `TargetBoxSize` and the candidate's aspect
  ratio when fitting with `contain` or `cover`.
- Parse the explicit `[contain | cover] <length> <length>` source size
  syntax in `sizes`.

Making `sizes="auto"` two-dimensional (using the box height and computed
`object-fit`), and using the `width`/`height` attributes as a default
aspect ratio for candidates without an `h` descriptor, are implemented
in follow-up CLs.

Bug: 572724710
Change-Id: I17fd93318d0955fbb3d6ce8aed7d085174671ddd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8559899
Reviewed-by: Stefan Zager <szager@chromium.org>
Commit-Queue: Noam Rosenthal <nrosenthal@google.com>
Cr-Commit-Position: refs/heads/main@{#1720204}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Oct 16, 2026
Implements the parsing parts of
whatwg/html#13053 behind the
`SrcsetTwoDimensionalSizes` runtime flag:

- Represent a resolved source size as a `TargetBoxSize` (`width`,
  optional `height`, and `object_fit`), and thread it through
  `SizesAttributeParser`, `HTMLImageElement::SourceSize()`, the preload
  scanner and `BestFitSource*`.
  One-dimensional sizes populate only `width`, so this is a no-op
  refactor for existing behavior.
- Parse the `<positive-integer>h` height descriptor in `srcset` when
  paired with a `w` descriptor, and compute each candidate's source
  concrete width from the `TargetBoxSize` and the candidate's aspect
  ratio when fitting with `contain` or `cover`.
- Parse the explicit `[contain | cover] <length> <length>` source size
  syntax in `sizes`.

Making `sizes="auto"` two-dimensional (using the box height and computed
`object-fit`), and using the `width`/`height` attributes as a default
aspect ratio for candidates without an `h` descriptor, are implemented
in follow-up CLs.

Bug: 572724710
Change-Id: I17fd93318d0955fbb3d6ce8aed7d085174671ddd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8559899
Reviewed-by: Stefan Zager <szager@chromium.org>
Commit-Queue: Noam Rosenthal <nrosenthal@google.com>
Cr-Commit-Position: refs/heads/main@{#1720204}
brave-builds pushed a commit to brave/chromium that referenced this pull request Oct 20, 2026
Second part of whatwg/html#13053, behind the
`SrcsetTwoDimensionalSizes` runtime flag.

When `sizes="auto"` is used, resolve it to the layout box's width and
height together with the computed `object-fit`, so that the source
concrete width of candidates with an `h` descriptor accounts for how the
image is fit into the box. The last auto-sizes size (used when the image
is not being rendered) stores the full `TargetBoxSize`.

A change to the computed `object-fit` of a lazy-loaded `sizes="auto"`
image is a relevant mutation, so re-run source selection (in a task, as
this is detected during style recalc).

Using the `width`/`height` attributes as a default aspect ratio for
candidates without an `h` descriptor is implemented in a follow-up CL.

Bug: 572724710
Change-Id: Ie4ce4feffc447102862fea230ba852ecdcc9dc3d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8563320
Commit-Queue: Noam Rosenthal <nrosenthal@google.com>
Reviewed-by: Stefan Zager <szager@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1722995}
beckysiegel pushed a commit to chromium/chromium that referenced this pull request Oct 22, 2026
Third part of whatwg/html#13053, behind the
`SrcsetTwoDimensionalSizes` runtime flag.

For srcset candidates without an `h` descriptor, use the dimension
attribute aspect ratio (from the `width`/`height` attributes of the
`<img>`, or of the `<source>` when it has one of them) as the source
aspect ratio when computing the source concrete width for a
two-dimensional size. This is also applied in the preload scanner.

Since these attributes now affect source selection, changing them on an
`<img>` or a previous sibling `<source>` is a relevant mutation, so re-run
source selection. To keep that re-selection side-effect free when the
selected URL did not change, `SelectSourceURL()` now only resets the
layout disposition when it actually updates the image loader.

Bug: 572724710
Change-Id: I2317a0b452ef8f0ca2438c41d8574312d19b9135
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8563321
Reviewed-by: Stefan Zager <szager@chromium.org>
Commit-Queue: Noam Rosenthal <nrosenthal@google.com>
Cr-Commit-Position: refs/heads/main@{#1724591}
@noamr
noamr marked this pull request as ready for review October 22, 2026 10:41
zcorpan added a commit to whatwg/spec-ai that referenced this pull request Oct 22, 2026
Distill generalizable review patterns from the multi-round reviews of whatwg/html#13053 and whatwg/html#12758 into the html-spec-review skill:

* Reactivity and mutation-hook parity.
* Re-validating DOM invariants after author script can run.
* Auditing shared parser algorithms across all parser contexts.
* CSS syntax and HTML microsyntax boundaries.
* Keeping notes, PR descriptions, and tests in sync after review fixes.
* WPT tests that mask failures, can't fail, or stall.

Also require span markup for continue and break in algorithm steps.

Add matching static checks:

* ALGO-LOOP-CONTROL-SPAN flags bare "continue." or "break." in algorithm blocks.
* WPT-EARLY-SCRIPT-CLOSE flags a literal </script> inside a JS comment or string literal in an inline script of an HTML test file, since it closes the script element early.
* WPT-UNGUARDED-TYPEERROR flags TypeError assertions on methods added in a spec diff when the test file doesn't check that the method exists, since calling an unimplemented method also throws TypeError.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Simon Pieters <zcorpan@gmail.com>
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Oct 23, 2026
Second part of whatwg/html#13053, behind the
`SrcsetTwoDimensionalSizes` runtime flag.

When `sizes="auto"` is used, resolve it to the layout box's width and
height together with the computed `object-fit`, so that the source
concrete width of candidates with an `h` descriptor accounts for how the
image is fit into the box. The last auto-sizes size (used when the image
is not being rendered) stores the full `TargetBoxSize`.

A change to the computed `object-fit` of a lazy-loaded `sizes="auto"`
image is a relevant mutation, so re-run source selection (in a task, as
this is detected during style recalc).

Using the `width`/`height` attributes as a default aspect ratio for
candidates without an `h` descriptor is implemented in a follow-up CL.

Bug: 572724710
Change-Id: Ie4ce4feffc447102862fea230ba852ecdcc9dc3d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8563320
Commit-Queue: Noam Rosenthal <nrosenthal@google.com>
Reviewed-by: Stefan Zager <szager@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1722995}
LunaStev pushed a commit to wavefnd-labs/blink that referenced this pull request Oct 27, 2026
Implements the parsing parts of
whatwg/html#13053 behind the
`SrcsetTwoDimensionalSizes` runtime flag:

- Represent a resolved source size as a `TargetBoxSize` (`width`,
  optional `height`, and `object_fit`), and thread it through
  `SizesAttributeParser`, `HTMLImageElement::SourceSize()`, the preload
  scanner and `BestFitSource*`.
  One-dimensional sizes populate only `width`, so this is a no-op
  refactor for existing behavior.
- Parse the `<positive-integer>h` height descriptor in `srcset` when
  paired with a `w` descriptor, and compute each candidate's source
  concrete width from the `TargetBoxSize` and the candidate's aspect
  ratio when fitting with `contain` or `cover`.
- Parse the explicit `[contain | cover] <length> <length>` source size
  syntax in `sizes`.

Making `sizes="auto"` two-dimensional (using the box height and computed
`object-fit`), and using the `width`/`height` attributes as a default
aspect ratio for candidates without an `h` descriptor, are implemented
in follow-up CLs.

Bug: 572724710
Change-Id: I17fd93318d0955fbb3d6ce8aed7d085174671ddd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8559899
Reviewed-by: Stefan Zager <szager@chromium.org>
Commit-Queue: Noam Rosenthal <nrosenthal@google.com>
Cr-Commit-Position: refs/heads/main@{#1720204}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Oct 27, 2026
Third part of whatwg/html#13053, behind the
`SrcsetTwoDimensionalSizes` runtime flag.

For srcset candidates without an `h` descriptor, use the dimension
attribute aspect ratio (from the `width`/`height` attributes of the
`<img>`, or of the `<source>` when it has one of them) as the source
aspect ratio when computing the source concrete width for a
two-dimensional size. This is also applied in the preload scanner.

Since these attributes now affect source selection, changing them on an
`<img>` or a previous sibling `<source>` is a relevant mutation, so re-run
source selection. To keep that re-selection side-effect free when the
selected URL did not change, `SelectSourceURL()` now only resets the
layout disposition when it actually updates the image loader.

Bug: 572724710
Change-Id: I2317a0b452ef8f0ca2438c41d8574312d19b9135
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8563321
Reviewed-by: Stefan Zager <szager@chromium.org>
Commit-Queue: Noam Rosenthal <nrosenthal@google.com>
Cr-Commit-Position: refs/heads/main@{#1724591}
lando-worker Bot pushed a commit to mozilla-firefox/firefox that referenced this pull request Nov 4, 2026
…dimensional sizes, a=testonly

Automatic update from web-platform-tests
Implement srcset 'h' descriptor and two-dimensional sizes

Implements the parsing parts of
whatwg/html#13053 behind the
`SrcsetTwoDimensionalSizes` runtime flag:

- Represent a resolved source size as a `TargetBoxSize` (`width`,
  optional `height`, and `object_fit`), and thread it through
  `SizesAttributeParser`, `HTMLImageElement::SourceSize()`, the preload
  scanner and `BestFitSource*`.
  One-dimensional sizes populate only `width`, so this is a no-op
  refactor for existing behavior.
- Parse the `<positive-integer>h` height descriptor in `srcset` when
  paired with a `w` descriptor, and compute each candidate's source
  concrete width from the `TargetBoxSize` and the candidate's aspect
  ratio when fitting with `contain` or `cover`.
- Parse the explicit `[contain | cover] <length> <length>` source size
  syntax in `sizes`.

Making `sizes="auto"` two-dimensional (using the box height and computed
`object-fit`), and using the `width`/`height` attributes as a default
aspect ratio for candidates without an `h` descriptor, are implemented
in follow-up CLs.

Bug: 572724710
Change-Id: I17fd93318d0955fbb3d6ce8aed7d085174671ddd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8559899
Reviewed-by: Stefan Zager <szager@chromium.org>
Commit-Queue: Noam Rosenthal <nrosenthal@google.com>
Cr-Commit-Position: refs/heads/main@{#1720204}

--

wpt-commits: d2727a54348e2af3f8fc7cbdfd4956d75927c938
wpt-pr: 63737
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this pull request Nov 4, 2026
…dimensional sizes, a=testonly

Automatic update from web-platform-tests
Implement srcset 'h' descriptor and two-dimensional sizes

Implements the parsing parts of
whatwg/html#13053 behind the
`SrcsetTwoDimensionalSizes` runtime flag:

- Represent a resolved source size as a `TargetBoxSize` (`width`,
  optional `height`, and `object_fit`), and thread it through
  `SizesAttributeParser`, `HTMLImageElement::SourceSize()`, the preload
  scanner and `BestFitSource*`.
  One-dimensional sizes populate only `width`, so this is a no-op
  refactor for existing behavior.
- Parse the `<positive-integer>h` height descriptor in `srcset` when
  paired with a `w` descriptor, and compute each candidate's source
  concrete width from the `TargetBoxSize` and the candidate's aspect
  ratio when fitting with `contain` or `cover`.
- Parse the explicit `[contain | cover] <length> <length>` source size
  syntax in `sizes`.

Making `sizes="auto"` two-dimensional (using the box height and computed
`object-fit`), and using the `width`/`height` attributes as a default
aspect ratio for candidates without an `h` descriptor, are implemented
in follow-up CLs.

Bug: 572724710
Change-Id: I17fd93318d0955fbb3d6ce8aed7d085174671ddd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8559899
Reviewed-by: Stefan Zager <szagerchromium.org>
Commit-Queue: Noam Rosenthal <nrosenthalgoogle.com>
Cr-Commit-Position: refs/heads/main{#1720204}

--

wpt-commits: d2727a54348e2af3f8fc7cbdfd4956d75927c938
wpt-pr: 63737

UltraBlame original commit: 0c74713bdbf7630f551e353ba718aa0734d8faaa
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this pull request Nov 4, 2026
…dimensional sizes, a=testonly

Automatic update from web-platform-tests
Implement srcset 'h' descriptor and two-dimensional sizes

Implements the parsing parts of
whatwg/html#13053 behind the
`SrcsetTwoDimensionalSizes` runtime flag:

- Represent a resolved source size as a `TargetBoxSize` (`width`,
  optional `height`, and `object_fit`), and thread it through
  `SizesAttributeParser`, `HTMLImageElement::SourceSize()`, the preload
  scanner and `BestFitSource*`.
  One-dimensional sizes populate only `width`, so this is a no-op
  refactor for existing behavior.
- Parse the `<positive-integer>h` height descriptor in `srcset` when
  paired with a `w` descriptor, and compute each candidate's source
  concrete width from the `TargetBoxSize` and the candidate's aspect
  ratio when fitting with `contain` or `cover`.
- Parse the explicit `[contain | cover] <length> <length>` source size
  syntax in `sizes`.

Making `sizes="auto"` two-dimensional (using the box height and computed
`object-fit`), and using the `width`/`height` attributes as a default
aspect ratio for candidates without an `h` descriptor, are implemented
in follow-up CLs.

Bug: 572724710
Change-Id: I17fd93318d0955fbb3d6ce8aed7d085174671ddd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8559899
Reviewed-by: Stefan Zager <szagerchromium.org>
Commit-Queue: Noam Rosenthal <nrosenthalgoogle.com>
Cr-Commit-Position: refs/heads/main{#1720204}

--

wpt-commits: d2727a54348e2af3f8fc7cbdfd4956d75927c938
wpt-pr: 63737

UltraBlame original commit: 0c74713bdbf7630f551e353ba718aa0734d8faaa
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this pull request Nov 4, 2026
…dimensional sizes, a=testonly

Automatic update from web-platform-tests
Implement srcset 'h' descriptor and two-dimensional sizes

Implements the parsing parts of
whatwg/html#13053 behind the
`SrcsetTwoDimensionalSizes` runtime flag:

- Represent a resolved source size as a `TargetBoxSize` (`width`,
  optional `height`, and `object_fit`), and thread it through
  `SizesAttributeParser`, `HTMLImageElement::SourceSize()`, the preload
  scanner and `BestFitSource*`.
  One-dimensional sizes populate only `width`, so this is a no-op
  refactor for existing behavior.
- Parse the `<positive-integer>h` height descriptor in `srcset` when
  paired with a `w` descriptor, and compute each candidate's source
  concrete width from the `TargetBoxSize` and the candidate's aspect
  ratio when fitting with `contain` or `cover`.
- Parse the explicit `[contain | cover] <length> <length>` source size
  syntax in `sizes`.

Making `sizes="auto"` two-dimensional (using the box height and computed
`object-fit`), and using the `width`/`height` attributes as a default
aspect ratio for candidates without an `h` descriptor, are implemented
in follow-up CLs.

Bug: 572724710
Change-Id: I17fd93318d0955fbb3d6ce8aed7d085174671ddd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8559899
Reviewed-by: Stefan Zager <szagerchromium.org>
Commit-Queue: Noam Rosenthal <nrosenthalgoogle.com>
Cr-Commit-Position: refs/heads/main{#1720204}

--

wpt-commits: d2727a54348e2af3f8fc7cbdfd4956d75927c938
wpt-pr: 63737

UltraBlame original commit: 0c74713bdbf7630f551e353ba718aa0734d8faaa
@noamr
noamr force-pushed the noamr/srcset-2d branch 2 times, most recently from 5949382 to 43d1ce7 Compare November 5, 2026 16:07
lando-worker Bot pushed a commit to mozilla-firefox/firefox that referenced this pull request Nov 6, 2026
…tonly

Automatic update from web-platform-tests
Make sizes="auto" two-dimensional

Second part of whatwg/html#13053, behind the
`SrcsetTwoDimensionalSizes` runtime flag.

When `sizes="auto"` is used, resolve it to the layout box's width and
height together with the computed `object-fit`, so that the source
concrete width of candidates with an `h` descriptor accounts for how the
image is fit into the box. The last auto-sizes size (used when the image
is not being rendered) stores the full `TargetBoxSize`.

A change to the computed `object-fit` of a lazy-loaded `sizes="auto"`
image is a relevant mutation, so re-run source selection (in a task, as
this is detected during style recalc).

Using the `width`/`height` attributes as a default aspect ratio for
candidates without an `h` descriptor is implemented in a follow-up CL.

Bug: 572724710
Change-Id: Ie4ce4feffc447102862fea230ba852ecdcc9dc3d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8563320
Commit-Queue: Noam Rosenthal <nrosenthal@google.com>
Reviewed-by: Stefan Zager <szager@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1722995}

--

wpt-commits: 080cafcc9fdc08e314a3949bcbe6bb5edc5b6b6d
wpt-pr: 64058
@noamr

noamr commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Open questions

Two pre-existing main behaviors surfaced while auditing the surrounding sizes and update the image data algorithms; neither is introduced by this PR, so I left them untouched, flagging in case follow-up issues are warranted:

  1. Non-first bare auto in parse a sizes attribute: Although the authoring grammar (<auto-source-size-list> = auto, <source-size-list>?) requires auto to be the first item and step 4.5 reports a parse error when unparsed size is not the first entry in sizes, step 4.6 (If img is not null and img allows auto-sizes) still runs for <img loading="lazy" sizes="(max-width: 0px) 10px, auto, 500px"> on main. Blink matches main's algorithm (treating non-first bare auto as auto after skipping a false media condition), whereas WebKit rejects non-first auto.
  2. Same-URL microtask fast path in update the image data: On main, when selected source equals last selected source and current request's state is completely available, step 15 queues an image-loading microtask and aborts without updating current pixel density to selected pixel density, so changing sizes without changing the winning URL leaves naturalWidth/naturalHeight density-corrected by the previous density until a different URL is selected.

Findings and fixes

Specification (whatwg/html#13053)

  • Media-conditioned auto in parse a sizes attribute (5bccf680e): In the refactor of parse a sizes attribute, <media-condition> was parsed before checking whether the remaining <source-size-value> was auto, which allowed <media-condition> auto (e.g. sizes="(min-width: 0px) auto") to enter the img allows auto-sizes branch instead of failing to parse and falling through to the next <source-size> item (diverging from <source-size-list> and Blink's SizesAttributeParser). Guarded the auto branch on <media-condition> not being present, and moved the invalid-auto parse error ahead of the final-item return null check so trailing invalid auto (e.g. <source sizes="auto">, <link imagesizes="auto">, or eager <img sizes="auto">) still reports a parse error before returning null.
  • Editorial & cross-reference cleanup (63bb0984c): Added for="img" / export definitions where appropriate, linked 'object-fit' values (contain, cover, scale-down, fill, none) to CSS Images, and tightened tuple/variable scoping across parse a sizes attribute, compute concrete object size, resolve a source size, and normalize the source densities.

Web Platform Tests (web-platform-tests/wpt#64025)

  • Eliminated 1D / non-implementing-engine false passes across all test suites (f21a26268b, 997e912965, e1d11d8b8f, 504c28142b, 8207c8373e, 227a5cfd21):
    • Replaced bare implicit-100vw fallbacks and tautological candidate orderings where a browser ignoring 2D sizes or h descriptors selected the same candidate as a 2D implementation (verified by running the suite with --no-enable-experimental).
    • Fixed invalid h descriptor subtests (0h, 50.5h, 50h 50h, 50h 5x, 5x 50h ) and height="0" / height="100%" dimension-attribute subtests in sizes-2d.html so un-dropped invalid candidates or unrejected percentage heights select a different reference image than conforming behavior.
    • Updated link-header-preload-imagesrcset-2d.html (.headers) to support DPR up to 4 with explicit 4000px / 3200px 1D fallbacks and reversed duplicate (w, h) candidate ordering so 1D fallback cannot collide with the first candidate.
  • Cross-engine precision & naturalWidth rounding (997e912965, cd13873840, d2d40011f5, 16609d2cd8):
    • Replaced non-dyadic 100px / 300px CSS lengths and 1x1 test images with powers of two (128px, 256px, 512px) and green-256x256.png to avoid float32 LayoutUnit boundary drift and floor(1 / density) === 0 collapse, while allowing both Math.floor (Blink) and Math.round (Gecko) for density-corrected naturalWidth / naturalHeight.
    • Shared exact integer w descriptors across candidates at fractional DPRs and fixed expectedDensity on the 2:1 cover subtests in select-an-image-source-2d.html.
  • Event-driven synchronization, viewport placement, & mandatory vs .optional split (3729c87006, dc5cbb6cf3, 13f66e0522, e315dd5e9a):
    • Replaced step_timeout sleeps with requestAnimationFrame / pre-attached onload promises, mounted loading="lazy" images inside the viewport so lazy-load intersection is guaranteed on small mobile/CI viewports, and flushed <iframe> layout before asserting vw / vh resolution.
    • Added coverage for <media-condition> auto rejection ((min-width: 0px) auto, contain 10px 1000px), display: none -> rendered sizes="auto" upgrades, Element.prototype.moveBefore preservation of last-auto-sizes-size, <picture> sibling <source> fallback, and CSS math functions (calc(), min(), max(), clamp()).
    • Kept static <iframe> vw/vh resolution in mandatory sizes-2d.html while moving dynamic iframe.style.height resize re-selection (#reacting-to-environment-changes without a media query) to select-an-image-source-2d-cached.optional.html.

lando-worker Bot pushed a commit to mozilla-firefox/firefox that referenced this pull request Nov 11, 2026
… for srcset source selection, a=testonly

Automatic update from web-platform-tests
Use the dimension attribute aspect ratio for srcset source selection

Third part of whatwg/html#13053, behind the
`SrcsetTwoDimensionalSizes` runtime flag.

For srcset candidates without an `h` descriptor, use the dimension
attribute aspect ratio (from the `width`/`height` attributes of the
`<img>`, or of the `<source>` when it has one of them) as the source
aspect ratio when computing the source concrete width for a
two-dimensional size. This is also applied in the preload scanner.

Since these attributes now affect source selection, changing them on an
`<img>` or a previous sibling `<source>` is a relevant mutation, so re-run
source selection. To keep that re-selection side-effect free when the
selected URL did not change, `SelectSourceURL()` now only resets the
layout disposition when it actually updates the image loader.

Bug: 572724710
Change-Id: I2317a0b452ef8f0ca2438c41d8574312d19b9135
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8563321
Reviewed-by: Stefan Zager <szager@chromium.org>
Commit-Queue: Noam Rosenthal <nrosenthal@google.com>
Cr-Commit-Position: refs/heads/main@{#1724591}

--

wpt-commits: 41a91b97e0ee996c8d9e6f9ac9beda5f014ab7cf
wpt-pr: 64084
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this pull request Nov 11, 2026
… for srcset source selection, a=testonly

Automatic update from web-platform-tests
Use the dimension attribute aspect ratio for srcset source selection

Third part of whatwg/html#13053, behind the
`SrcsetTwoDimensionalSizes` runtime flag.

For srcset candidates without an `h` descriptor, use the dimension
attribute aspect ratio (from the `width`/`height` attributes of the
`<img>`, or of the `<source>` when it has one of them) as the source
aspect ratio when computing the source concrete width for a
two-dimensional size. This is also applied in the preload scanner.

Since these attributes now affect source selection, changing them on an
`<img>` or a previous sibling `<source>` is a relevant mutation, so re-run
source selection. To keep that re-selection side-effect free when the
selected URL did not change, `SelectSourceURL()` now only resets the
layout disposition when it actually updates the image loader.

Bug: 572724710
Change-Id: I2317a0b452ef8f0ca2438c41d8574312d19b9135
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8563321
Reviewed-by: Stefan Zager <szagerchromium.org>
Commit-Queue: Noam Rosenthal <nrosenthalgoogle.com>
Cr-Commit-Position: refs/heads/main{#1724591}

--

wpt-commits: 41a91b97e0ee996c8d9e6f9ac9beda5f014ab7cf
wpt-pr: 64084

UltraBlame original commit: 32041176a193e436160930d3e4d7c1cbcebcab11
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this pull request Nov 11, 2026
… for srcset source selection, a=testonly

Automatic update from web-platform-tests
Use the dimension attribute aspect ratio for srcset source selection

Third part of whatwg/html#13053, behind the
`SrcsetTwoDimensionalSizes` runtime flag.

For srcset candidates without an `h` descriptor, use the dimension
attribute aspect ratio (from the `width`/`height` attributes of the
`<img>`, or of the `<source>` when it has one of them) as the source
aspect ratio when computing the source concrete width for a
two-dimensional size. This is also applied in the preload scanner.

Since these attributes now affect source selection, changing them on an
`<img>` or a previous sibling `<source>` is a relevant mutation, so re-run
source selection. To keep that re-selection side-effect free when the
selected URL did not change, `SelectSourceURL()` now only resets the
layout disposition when it actually updates the image loader.

Bug: 572724710
Change-Id: I2317a0b452ef8f0ca2438c41d8574312d19b9135
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8563321
Reviewed-by: Stefan Zager <szagerchromium.org>
Commit-Queue: Noam Rosenthal <nrosenthalgoogle.com>
Cr-Commit-Position: refs/heads/main{#1724591}

--

wpt-commits: 41a91b97e0ee996c8d9e6f9ac9beda5f014ab7cf
wpt-pr: 64084

UltraBlame original commit: 32041176a193e436160930d3e4d7c1cbcebcab11
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this pull request Nov 11, 2026
… for srcset source selection, a=testonly

Automatic update from web-platform-tests
Use the dimension attribute aspect ratio for srcset source selection

Third part of whatwg/html#13053, behind the
`SrcsetTwoDimensionalSizes` runtime flag.

For srcset candidates without an `h` descriptor, use the dimension
attribute aspect ratio (from the `width`/`height` attributes of the
`<img>`, or of the `<source>` when it has one of them) as the source
aspect ratio when computing the source concrete width for a
two-dimensional size. This is also applied in the preload scanner.

Since these attributes now affect source selection, changing them on an
`<img>` or a previous sibling `<source>` is a relevant mutation, so re-run
source selection. To keep that re-selection side-effect free when the
selected URL did not change, `SelectSourceURL()` now only resets the
layout disposition when it actually updates the image loader.

Bug: 572724710
Change-Id: I2317a0b452ef8f0ca2438c41d8574312d19b9135
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8563321
Reviewed-by: Stefan Zager <szagerchromium.org>
Commit-Queue: Noam Rosenthal <nrosenthalgoogle.com>
Cr-Commit-Position: refs/heads/main{#1724591}

--

wpt-commits: 41a91b97e0ee996c8d9e6f9ac9beda5f014ab7cf
wpt-pr: 64084

UltraBlame original commit: 32041176a193e436160930d3e4d7c1cbcebcab11
@noamr
noamr requested a review from zcorpan November 25, 2026 11:32
@noamr noamr added the topic: img Images: img, picture, srcset and sizes, image loading and decoding, and image maps label Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic: img Images: img, picture, srcset and sizes, image loading and decoding, and image maps

Development

Successfully merging this pull request may close these issues.

sizes=auto images shouldn't use concrete object width to select source Add height-based selection to srcset/sizes

1 participant