Skip to content

Spec text for width/height APIs on not-rendered images (returning "density-corrected" natural width and height) does not reflect reality of what browsers do. #12573

@dholbert

Description

@dholbert

What is the issue with the HTML Standard?

This is a followup to #11287, specifically this comment:
#11287 (comment)

The patch there made the spec reflect reality in one way ("Make naturalWidth & naturalHeight return non-0 when the image lacks a dimension"), but the thing that I referred to in #11287 (comment) part (2) is still a spot where the spec doesn't match reality.

The spec still uses "density-corrected" to describe the width and height IDL attributes for images-that-are-not-being-rendered:
https://html.spec.whatwg.org/multipage/embedded-content.html#dom-img-width

The IDL attributes width and height must return [...text for images that are being rendered...]; or else the density-corrected natural width and height of the image, in CSS pixels, if the image has density-corrected natural width and height and is available but is not being rendered;

Browsers don't actually do density-correction in this case. You can see this using the testcase that I linked in #11287 (comment) part (2), and also in the WPT that we have for this area of behavior, specifically this section where we increase image density to 2 but decline-to-scale-up our expected width and height attributes for the not-rendered case:
https://github.com/web-platform-tests/wpt/blob/master/html/semantics/embedded-content/the-img-element/naturalWidth-naturalHeight-width-height.html#L331-L335

@annevk what do you think we should do here? Should we make a followup tweak to remove density-corrected from this line of spec text? (That term is linked, and I guess the link needs to change, too -- it doesn't quite make sense to link to https://html.spec.whatwg.org/multipage/images.html#density-corrected-intrinsic-width-and-height anymore. But also, there isn't a great new defined term that we can link to. Maybe we should still link to that section and just describe it as "density-corrected natural width and height, assuming a preferred density of 1", or something along those lines? That seems to be what we're doing...)

Alternately, maybe we should just fix browsers to do what the spec says here? I'm not sure if there's a good reason to not density-correct .width and .height for not-rendered images. Maybe we can change to remove this weird density-dependent difference between the .natural{Width/Height} and .{width/height} attributes...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions