Repository navigation
Description
Problem:
Implementing aspect ratios during the first layout calculation for when various aspect ratios are utilized, such as with art direction.
Avoid any extra layout calculation's after initial layout. (avoiding page jumps!)
Avoid writing any CSS for the aspect ratio.
Avoid needing custom JS to do any of this.
Use Case:
Using multiple <source> 's within <picture> or <video>
Requirements:
Aspect-ratio MUST be known for each source.
(ideally it should match the intrinsic ratio of source asset, otherwise when the asset loads the intrinsic ratio changes and may cause layout recalc? which we want to avoid!)
New attributes(s) for <source>:width="1600" height="900" (16/9 ratio)
Both width and height of the source must be supplied for a ratio to be calculated.
e.g. <source srcset="https://via.placeholder.com/600x279" media="(max-width: 599px)" width="600" height="279">
My thoughts on implementation for <picture>
Either the <img> inside <picture> or the <picture> element itself will have the aspect ratio applied to it.
<picture>
<source srcset="https://via.placeholder.com/600x279" media="(max-width: 599px)" width="600" height="279">
<source srcset="https://via.placeholder.com/1500x300" media="(max-width: 991px)" width="1500" height="300">
<img src="https://via.placeholder.com/1500x300" width="1500" height="300">
</picture>
Activity
[-]Utilizing Aspect-Ratio for Art Direction (Multiple Sources with various Aspect Ratios known) [/-][+]Utilizing Aspect-Ratio with Art Direction (Multiple Sources with various Aspect Ratios known) [/+]yoavweiss commentedon Oct 3, 2019
As I suggested on WICG/intrinsicsize-attribute#16 (comment), I think we can update the update the image data algorithm to pick the aspect ratio from the selected source.
For consistency, it seems like it would be better to add
widthandheightattributes.AndresInSpace commentedon Oct 3, 2019
@yoavweiss
I agree on utilizing
width="" height=""instead ofratio=""for consistency.I will update my post to reflect this.
One question regarding changing the algorithm of update the image data:
Would this cause a re-calc of layout or would this pick the proper source before the first layout calc? I am unsure of the order of things here.
jensimmons commentedon Oct 7, 2019
I agree that the best solution is to have Authors put
widthandheightattributes on each source inside<picture>(andvideoand anyplace elsesourceis used for visual media) — and have the browser act as if the width and height attributes are being swapped into the<img>element in exactly the same way thesrcattribute is swapped.I would not apply this to the
pictureelement. (Which reminds me @fantasai and @emilio of that conversation we had when we discovered all the CSS being applied to picture that should be removed... thatpictureshould havedisplay: contentsapplied instead — we should find & file that issue).@AndresInSpace This should apply to the first layout calculation. In the moment when the browser decides which image to use, it should grab the width & height data, and use it in the first paint. Skipping over any other ideas of what layout should be. Once the height & width data is transferred to
img, along withsrc— everything else should happen just as if the IMG only had one URL, one height, one width, and there were no other sources.zcorpan commentedon Oct 8, 2019
Nope,
videodoesn't do art direction. #4544AndresInSpace commentedon Oct 8, 2019
@jensimmons Perfect.
@zcorpan I think the arguments for it carries more weight than the argument against it. I've posted my thoughts over in #4544
Mapping HTML attributes width/height to the default aspect ratio of <…
Crissov commentedon Jun 16, 2020
Does this also handle image formats like HEIF which, as far as I understand, can have multiple pictures inside that do not need to have all the same dimensions and ratios (though usually do)?
[AspectRatio] Add a test for <picture>
[AspectRatio] Add a test for <picture>
[AspectRatio] Add a test for <picture>
[AspectRatio] Add a test for <picture>
Bug 1646999 [wpt PR 24256] - [AspectRatio] Add a test for <picture>, …
Bug 1646999 [wpt PR 24256] - [AspectRatio] Add a test for <picture>, …
Mapping HTML attributes width/height to the default aspect ratio of <…
patricknelson commentedon Mar 4, 2021
For reference, this is now documented at (via PR #5894):
https://html.spec.whatwg.org/multipage/embedded-content.html#the-source-element
Thank you for adding this to the spec! 🎉
cbiesinger commentedon Mar 4, 2021
It will also ship in Chrome 90! I believe Firefox is also working on it, don't know about their schedule.
hecktarzuli commentedon May 6, 2022
This is in Safari 15
hecktarzuli commentedon Jul 6, 2022
For those looking for FF support, this seems to be the Firefox tracking for this: https://bugzilla.mozilla.org/show_bug.cgi?id=1694741
otabekshoyimov commentedon Dec 6, 2022
This has landed on Firefox 108 Developer Edition
Add width and height attributes to source elements
Bug 1646999 [wpt PR 24256] - [AspectRatio] Add a test for <picture>, …