This site is mobile accessible. Press the "Tap Here" button to use a smaller font-size.
Smartphone icons created by Freepik - Flaticon
The HTML
element allows you to display different pictures for different devices or screen sizes.The HTML
element gives web developers more flexibility in specifying image resources. The element contains one or more elements, each referring to different images through the attribute. This way the browser can choose the image that best fits the current view and/or device. Each element has a media attribute that defines when the image is the most suitable.Show different images for different screen sizes:
<picture> <source media="(min-width: 700px)" srcset="img_girl.jpg"> <source media="(min-width: 465px)" srcset="img_food.jpg"> <img src="img_car.jpg"> </picture>
Note: Always specify an
element as the last child element of the element. The element is used by browsers that do not support the element, or if none of the tags match.There are two main purposes for the
element:If you have a small screen or device, it is not necessary to load a large image file. The browser will use the first
element with matching attribute values, and ignore any of the following elements.Some browsers or devices may not support all image formats. By using the
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.The browser will use the first image format it recognizes:
<picture> <source srcset="img_avatar.png"> <source srcset="img_girl.jpg"> <img src="img_programming.gif" alt="computer programmer" style="width:auto;"> </picture>
Note: The browser will use the first
element with matching attribute values, and ignore any following elements.Tag | Description |
---|---|
<img> | Defines an image |
<map> | Defines an image map |
<area> | Defines a clickable area inside an image map |
<picture> | Defines a container for multiple image resources |
For a complete list of all available HTML tags, visit HTML Tag Reference.