donquixote
donquixote

Reputation: 5471

Do srcset and sizes refer to device pixels or layout pixels?

Questions about the <img srcset=".." sizes=".."/> html tag + attributes for responsive images.

My own guess would be that sizes refers to layout pixels always. But would prefer if this can be confirmed.

(Ideally I would want to serve different jpg quality depending on the pixel density on the device.. Retina = low quality, high resolution. But this is probably a separate question)

Full scenario here: Responsive img/srcset/sizes: Different jpg quality depending on device pixel density?

EDIT: When I say "device pixels", I really mean the physical pixels on the device.

Upvotes: 1

Views: 768

Answers (1)

zcorpan
zcorpan

Reputation: 1273

But the question is, how does the browser pick one of the provided images? Based on device pixels, or based on css pixels?

This is technically up to the implementation, but the idea is that it should be based on device pixels; if you have a screen with a high pixel density, you want a bigger image. If you zoom in, you may also want a bigger image.

Does the media query in the sizes attribute refer to device pixels or to layout pixels? Do image width px in the sizes attribute refer to device pixels or to layout pixels?

These are both CSS px.

Upvotes: 2

Related Questions