Allow <source>
elements to query container sizes
#10182
Labels
addition/proposal
New features or enhancements
needs implementer interest
Moving the issue forward requires implementers to express interest
topic: img
What problem are you trying to solve?
HTML's
<source>
elements are able to query viewport width with themedia
attribute to swap image sources based on device size. Now that container queries are part of Baseline 2023,<source>
attributes should be able to swap image sources based on the size of a parent container as wellWhat solutions exist today?
DIY JavaScript solutions can alter the
src
attribute of<img>
elements, but this still requires the rapid-fire callbacks of aresizeObserver
to handle. JS-based solutions could be improved with awindow.matchMedia
analog for container queries as proposed here, but a native HTML solution would be ideal.How would you solve it?
Similar to the existing
media
attribute, a newcontainer
attribute would be added and its value used to query the inline size of a container. This would query the width of the containingpicture
element to select the preferred source.Alternatively, the container could also accept a
<container-name>
value that's been defined in CSS to instead query some container higher in the DOM.Anything else?
No response
The text was updated successfully, but these errors were encountered: