Flower.jpg WORK
The <picture>, <source>, and <img> tags, including how they are ordered relative to each other, all interact to achieve this end result.<picture> #The <picture> tag provides a wrapper for zero or more <source> tags and one <img> tag.<source> #The <source> tag specifies a media resource.The browser uses the first listed source that's in a format it supports. If the browser does not support any of the formats listed in the <source> tags, it falls back to loading the image specified by the <img> tag.Gotchas- The <source> tag for the "preferred" image format (in this case that is WebP) should be listed first, before other <source> tags. - The value of the type attribute should be the MIME type corresponding to the image format. An image's MIME type and its file extension are often similar, but they aren't necessarily the same thing (e.g. .jpg vs. image/jpeg).<img> #The <img> tag is what makes this code work on browsers that don't support the <picture> tag. If a browser does not support the <picture> tag, it will ignore the tags it doesn't support. Thus, it only "sees" the <img src="flower.jpg" alt=""> tag and loads that image.GotchasThe <img> tag should always be included, and it should always be listed last, after all <source> tags.The resource specified by the <img> tag should be in a universally supported format (e.g. JPEG), so it can be used as a fallback.Reading the HTTP Accept header #If you have an application back end or web server that allows you to rewrite requests, you can read the value of the HTTP Accept header, which will advertise what alternative image formats are supported:
flower.jpg
041b061a72