Responsive image using picture element
suggest changeCode
<picture>
<source media="(min-width: 600px)" srcset="large_image.jpg">
<source media="(min-width: 450px)" srcset="small_image.jpg">
<img src="default_image.jpg" alt="">
</picture>
Usage
To show different images at different screen widths, include every candidate in a <source> inside <picture>, as in the example. The browser uses the first <source> whose media query matches, so order matters.
Result
- On screens wider than 600px, it shows
large_image.jpg - On screens wider than 450px but no wider than 600px, it shows
small_image.jpg - Otherwise, it shows
default_image.jpg
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents