Skip to content

Consult the dimension attributes for width and height when not rendered - #12840

Open
annevk wants to merge 1 commit into
mainfrom
annevk/dimension-attributes-not-rendered
Open

Consult the dimension attributes for width and height when not rendered#12840
annevk wants to merge 1 commit into
mainfrom
annevk/dimension-attributes-not-rendered

Conversation

@annevk

@annevk annevk commented Aug 25, 2026

Copy link
Copy Markdown
Member

The width and height IDL attributes of img elements, and of input
elements in the Image Button state, returned the natural dimensions when
the element was not being rendered. All browsers instead return the width
and height content attributes.

Drop the "has density-corrected natural width and height" condition as
4ff60b0 gave every available image a
300x150 fallback.

Tests: web-platform-tests/wpt#61080

Closes #12573.

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


/embedded-content-other.html ( diff )
/embedded-content.html ( diff )
/input.html ( diff )

The width and height IDL attributes of img elements, and of input
elements in the Image Button state, returned the natural dimensions when
the element was not being rendered. All browsers instead return the width
and height content attributes.

Drop the "has density-corrected natural width and height" condition as
4ff60b0 gave every available image a
300x150 fallback.

Tests: web-platform-tests/wpt#61080

Closes #12573.
@zcorpan

zcorpan commented Aug 27, 2026

Copy link
Copy Markdown
Member

Opus+Codex review:

1. The input path can be handed absent natural dimensions, and engines diverge there. The img path goes through density-corrected natural width and height, which ends in the default sizing algorithm with a 300×150 default object size — that is exactly why the "has density-corrected natural width and height" condition could be dropped. The input path (source:51397-51404) instead says "the natural width and height of that image", and CSS natural dimensions can be absent on one axis or present only as a ratio. That value then flows into a parameter declared as "a struct consisting of a width and a height, or null", which cannot represent it.

This is not hypothetical. <input type=image> with display:none, natural dimensions from the SVG:

SVG Chrome Canary Firefox 152 Safari TP
viewBox='0 0 600 200' (ratio only) 300×100 300×100 600×200
width='60' (width only) 60×150 60×150 300×150

Chromium and Gecko apply the default sizing algorithm; WebKit doesn't. The spec should say which, presumably by routing input through the same 300×150 default sizing the img path gets.

2. Nothing bounds the parsed attribute value to unsigned long. Rules for parsing non-negative integers has no upper bound (source:5608-5625), so <img width="4294967296"> while not rendered returns 4294967296 from an unsigned long getter with no [EnforceRange]/[Clamp] — Web IDL's ToUint32 wraps it to 0. Measured on a 100×100 image, display:none:

  • width="2147483648" → Chrome Canary 2147483648, Firefox 100, Safari TP 100
  • width="4294967296" and width="99999999999" → 100 in all three

No engine wraps. Steps 4.2 and 5.2 should treat an out-of-range value as an error and fall through to the natural dimension.

3. Step 1 lost the "of the image" precision. The old input text returned "the rendered width and height of the image"; the shared algorithm returns the element's rendered width and height. For <img style="box-sizing:border-box;width:100px;border:7px;padding:3px">, .width is 80 in Chrome Canary, Firefox and Safari TP, while offsetWidth is 100 — it's the content box, not the element's rendered box. Since input type=image has a UA border and padding, this now matters for both elements.

4. Both domintros are stale. source:31586 and source:54712 still say "These attributes return the actual rendered dimensions of the image, or 0 if the dimensions are not known." That's now wrong on both counts, and it's the only description of these attributes in the developer's edition. Also, the new sentence at source:45322-45325 links the words "img" and "input" to dom-img-height/dom-input-height rather than the element definitions.

Minor: step 3 says "in CSS pixels" but steps 4–5 don't; and the img wrapper reads "return the width of this's dimensions" while the input wrapper reads "return the respective component of the result of determining the dimensions of this" for the same shape of thing.

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

2 participants