Is there a srcset equivalent for css background image

Martin Algesten picture Martin Algesten · Nov 7, 2014 · Viewed 52.3k times · Source

img with srcset attribute looks like a great way of doing responsive images. Is there an equivalent syntax that works in css background-image property?

HTML

<img src="small.jpg" srcset="medium.jpg 1000w, large.jpg 2000w" alt="yah">

CSS

.mycontainer {
    background: url(?something goes here?);
}

Answer

Yoav Weiss picture Yoav Weiss · Nov 8, 2014

image-set is the equivalent CSS feature. We should add equivalent srcset functionality (defining resources according to their dimensions) to the spec.

Currently it's only implemented in Safari, Chrome and Opera with the -webkit- prefix, and it only supports the x descriptors.