Publish in HTML Tutorial el 25/05/2025 14:53
The HTML <picture>
element serves as a container for zero or more <source>
elements and one <img>
element. Its primary purpose is to provide alternative image resources for different display/device scenarios, enabling responsive images without using CSS or JavaScript.
Key features:
<img>
if no sources matchHere's the basic structure of the <picture>
element:
This example shows different images based on viewport width:
Serve WebP to supporting browsers, fallback to JPEG:
Serve higher resolution images to high-DPI devices:
This example shows how to change the picture source using JavaScript:
Dynamically update image sources when window is resized:
<img>
tag as the last child - it serves as the fallback<source>
<source>
sizes
attribute with srcset
for better controlThe <picture>
element is supported in all modern browsers (Chrome, Firefox, Safari, Edge) since 2015. For older browsers, the <img>
fallback ensures your content remains accessible.
The <style> HTML element contains style information for a document, or part of a document. ...
The <strong> element is used to indicate that its content has strong importance, seriousnes...
The <span> element is an inline container used to mark up a part of a text or document. Unl...
The <source> element is used to specify multiple media resources for media elements like &l...
The <small> element is used to represent side-comments and small print, typically for discl...
HTML <section> Element: The Complete Guide The <section> element is a semantic HTML ...