6 ms·
MDN says that img tag purpose is not just to serve as a fallback, but also to specify size “and other attributes”. Does it also include alt attribute? This is i
by d_bud 4y ago
MDN says that img tag purpose is not just to serve as a fallback, but also to specify size “and other attributes”. Does it also include alt attribute? This is important. Can someone confirm that?
- capableweb 4y agoYes, all attributes from <img> applies to the selected image, not just width or height.
- seanhunter 4y agoThe article says The final <img> tag also specifies common attributes like width, height and alt text. Those attributes will apply regardless of which source the browser chooses! The official spec for the picture element is here https://html.spec.whatwg.org/multipage/embedded-content.html#the-picture-element https://html.spec.whatwg.org/multipage/embedded-content.html... and it says The picture element is a container which provides multiple sources to its contained img element to allow authors to declaratively control or give hints to the user agent about which image resource to use, based on the screen pixel density, viewport size, image format, and other factors. It represents its children. So I read that as the alt text (as well as other attributes other than the actual src url) come from the img tag
- eyelidlessness 4y agoAdding something I don’t currently see mentioned explicitly: the img tag is the actual presented media element, picture/source are not displayed without an img tag. So the img tag itself isn’t even a fallback, only its src attribute.
- masswerk 4y agoIt's also the img tag that you style in CSS. So for all layout purpose, it's still the img element that defines the container and the picture element is more a syntactical bracket to associate other source-sets with it. (This isn't very HTML-y, but, well…)