I have following snap-points: 480px, 900px, 1800px, 2400px.
and this markup:
Device-pixel ratio is the number of device pixels per CSS pixel which is related to:
srcset attribute & x descriptorOn tag, the x descriptor in the srcset attribute is used to define the device-pixel ratio. So in:
src attribute (image.jpg) will be used.srcset attribute & w descriptorIf you want a different image on a larger or smaller viewport, the w descriptor in srcset and a new attribute (sizes) comes into play:
This mentions that the width of the first image is 200px, second image is 400px, and third image is 600px. Also, if the user’s screen is 150 CSS pixels wide, this equates to the following in terms of x descriptors:
sizes attributeThe actual implementation where you’d want a different size image (different height, width) on different screen sizes is accomplished by using sizes attribute along with the w descriptor of srcset attribute.
If the browser width is 500 CSS pixels, the image will be displayed 250px wide (because of 50vw). Now, this is equivalent to specifying:
So, for a 1.5x display, image-2x.jpg will be downloaded by a browser, since it gives a device-pixel ratio of 1.6x (which is most suitable for a 1.5x display).
You have mentioned that you have emulated a 480px CSS width screen.
Because you have set sizes to 100vw, that is equivalent to specifying:
There is chance you have 3x display, and thus the browser downloads boat-1800.jpg file.
Questions
Oddly, when I tested this on Chrome on iOS the browser actually downloaded boat-2400.jpg which is even more worrying.
That would be due to the higher Device-pixel ratio of your iOS device, which is likely to be something near 5.
Have I missed something here?
I dont think so.
I imagine I don't need the sizes attribute because I have the image set to 100vw in all views
The value of sizes is 100vw by default. But if you want to use w descriptor and want to have something other than 100vw for your sizes, you need sizes attribute.