Image Picture Elements HTML
Image Picture Elements HTML
❮ PreviousNext ❯
The HTML <picture> element allows you to display different pictures for
different devices or screen sizes.
Example
Show different images for different screen sizes:
<picture>
<source media="(min-width: 650px)" srcset="img_food.jpg">
<source media="(min-width: 465px)" srcset="img_car.jpg">
<img src="img_girl.jpg">
</picture>
Try it Yourself »
Note: Always specify an <img> element as the last child element of
the <picture> element. The <img> element is used by browsers that do not
support the <picture> element, or if none of the <source> tags match.
ADVERTISEMENT
1. Bandwidth
If you have a small screen or device, it is not necessary to load a large image
file. The browser will use the first <source> element with matching attribute
values, and ignore any of the following elements.
2. Format Support
Some browsers or devices may not support all image formats. By using
the <picture> element, you can add images of all formats, and the browser will
use the first format it recognizes, and ignore any of the following elements.
Example
The browser will use the first image format it recognizes:
<picture>
<source srcset="img_avatar.png">
<source srcset="img_girl.jpg">
<img src="img_beatles.gif" alt="Beatles" style="width:auto;">
</picture>
Try it Yourself »
Note: The browser will use the first <source> element with matching attribute
values, and ignore any following <source> elements.
Exercise?
One of these elements is NOT a legal HTML element, which one?
Submit Answer »
For a complete list of all available HTML tags, visit our HTML Tag Reference.