Skip to content

Make naturalWidth & naturalHeight return non-0 when the image lacks a dimension#12382

Merged
annevk merged 1 commit intomainfrom
annevk/naturalWidth-Height
Apr 22, 2026
Merged

Make naturalWidth & naturalHeight return non-0 when the image lacks a dimension#12382
annevk merged 1 commit intomainfrom
annevk/naturalWidth-Height

Conversation

@annevk
Copy link
Copy Markdown
Member

@annevk annevk commented Apr 16, 2026

Unfortunately the more correct behavior was never implemented widely enough and web content started to depend on these properties being non-0.

We take special care that dimensions that are missing do not get divided by density so we return the same values for them as CSS (300 by 150).

Fixes #11287.

(See WHATWG Working Mode: Changes for more details.)


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

… dimension

Unfortunately the more correct behavior was never implemented widely enough and web content started to depend on these properties being non-0.

We take special care that dimensions that are missing do not get divided by density so we return the same values for them as CSS (300 by 150).
annevk added a commit to web-platform-tests/wpt that referenced this pull request Apr 17, 2026
The change from the tentative version is that image density does not impact the 300 x 150 fallback so when intrinsic dimensions are missing we use the same values in the API and rendering.

This complements whatwg/html#12382.
@annevk annevk changed the title Make naturalWidth & naturalHeight return non-0 when the image lacks a… Make naturalWidth & naturalHeight return non-0 when the image lacks a dimension Apr 17, 2026
@dholbert
Copy link
Copy Markdown
Contributor

* [ ]  At least two implementers are interested (and none opposed):
  
  * WebKit
  * …

I'm on board with this change, on behalf of Firefox/Gecko, FWIW. Thank you for doing this, @annevk !

@dholbert
Copy link
Copy Markdown
Contributor

I skimmed the commit itself and didn't see anything obviously incorrect.

@annevk let me know if you'd like me to officially review in the github review UI. I'm happy to do so if that's useful -- but also, I'm not an html-spec-editor, so I might not satisfy the "reviewers with write access" landing-condition. (And I might also be oblivious to bespoke syntax/formatting requirements in the html spec etc.)

annevk added a commit to web-platform-tests/wpt that referenced this pull request Apr 22, 2026
The change from the tentative version is that image density does not impact the 300 x 150 fallback so when intrinsic dimensions are missing we use the same values in the API and rendering.

This complements whatwg/html#12382.
annevk added a commit to web-platform-tests/wpt that referenced this pull request Apr 22, 2026
The change from the tentative version is that image density does not impact the 300 x 150 fallback so when intrinsic dimensions are missing we use the same values in the API and rendering.

This complements whatwg/html#12382.
@annevk annevk merged commit 4ff60b0 into main Apr 22, 2026
2 checks passed
@annevk annevk deleted the annevk/naturalWidth-Height branch April 22, 2026 16:12
lando-worker Bot pushed a commit to mozilla-firefox/firefox that referenced this pull request Apr 28, 2026
…ight for SVG, a=testonly

Automatic update from web-platform-tests
HTML: correct naturalWidth and naturalHeight for SVG

The change from the tentative version is that image density does not impact the 300 x 150 fallback so when intrinsic dimensions are missing we use the same values in the API and rendering.

This complements whatwg/html#12382.
--

wpt-commits: 4a0dd7000d8b0b174f7f857d8362708fa8f0cdd0
wpt-pr: 59304
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

Spec text for naturalWidth and naturalHeight behavior isn't web-compatible, for cases where attributes are missing

3 participants