HTML - Picture Element and Responsive Images
Modern websites must look good on mobiles, tablets, and desktops. A single image size does not work well for all devices. This is where responsive images come in. HTML provides tools to load the right image at the right time, improving performance and user experience.
What Is the <picture> Element?
The <picture> element allows the browser to choose the most suitable image based on screen size, resolution, or device conditions. It works together with <source> and <img> tags.
Think of <picture> as a decision maker that tells the browser:
“Use this image on small screens, that image on large screens.”
Basic <picture> Example
<picture>
<source media="(max-width: 600px)" srcset="small.jpg">
<source media="(max-width: 1024px)" srcset="medium.jpg">
<img src="large.jpg" alt="Responsive image">
</picture>
How this works:
-
Mobile screens get
small.jpg -
Tablets get
medium.jpg -
Large screens get
large.jpg -
<img>is a fallback if<picture>is not supported
Why Use the <picture> Element?
-
Faster page loading (smaller images for mobiles)
-
Better image quality on large screens
-
Saves user data
-
Improves SEO and Core Web Vitals
srcset and sizes (Without <picture>)
You can also make images responsive using only <img>:
<img
src="default.jpg"
srcset="small.jpg 480w, medium.jpg 768w, large.jpg 1200w"
sizes="(max-width: 600px) 480px, (max-width: 1024px) 768px, 1200px"
alt="Responsive image">
The browser automatically selects the best image based on screen width.
When to Use What?
-
Use
<picture>when:-
You want different images for different devices
-
Art direction matters (cropping changes)
-
-
Use
srcsetwhen:-
Same image, different sizes
-
Performance optimization only
-
-
Responsive images make websites faster and smarter
-
<picture>= multiple image choices -
srcset= size optimization -
Always include
altfor accessibility
Using responsive images is a best practice in modern web development.