The tag gives web developers more flexibility in specifying image resources.
The most common use of the element will be for art direction in responsive designs.
The element contains two tags:
one or more
one tag.
The tag is useful for showing the right image on different devices, making websites faster and more user-friendly.
The tag is a container that contains one or more element. The browser checks each
tag.
The <picture> tag itself does not have many attributes. Most attributes are used with the <source> and <img> elements inside it.
srcset
Specifies the image file to display.
Used inside the <source> tag.
media
Defines the screen size or device condition.
The browser displays the image only if the condition is true.
type
Specifies the image format, such as WebP or PNG.
Helps the browser choose a supported image formala.
src
Specifies the default image.
Used inside the <img> tag.
alt
Provides alternative text if the image cannot be displayed.
Improves accessibility.
Summary Table
Attribute - Description
srcset - Specifies the image file to display.
media - Sets the screen size condition.
type - Specifies the image format.
src - Specifies the default image.
alt - Provides alternative text for the image.
Top comments (0)