Great answer: this is possible without javascript for a while.
In the future, the <picture> element will be exactly what will be used and necessary. HTML for it is as follows
<picture> <source srcset="examples/images/large.jpg" media="(min-width: 1000px)"> <source srcset="examples/images/medium.jpg" media="(min-width: 800px)"> <source srcset="examples/images/small.jpg"> <img srcset="examples/images/small.jpg" alt="Desciption of image"> </picture>
This is essentially the same method as below, but the writing form is simplified and serves img , not background-image . Starting with writing this answer, we can use a polyfill to use this format or @media request
CSS2 media text types introduced @media queries that allow us to influence different page styles based on viewport sizes, among many other things. This allows you to serve large images as background images only if they are needed. An example of its use is
.myImg { background-image:url(myurlSmall.png); } @media (min-width:400px) { .myImg { background-image:url(myurlMedium.png); } } @media (min-width:1200px) { .myImg { background-image:url(myurlLarge.png); } }
source share