Martin Algesten Martin Algesten - 5 months ago 110
HTML Question

Is there a srcset equivalent for css background image

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

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's only support the x descriptors.