Resolution Media Queries
suggest changeUse the standard resolution media feature when an asset genuinely needs to vary with output density:
.logo {
background-image: url("logo.png");
}
@media (resolution >= 2dppx) {
.logo {
background-image: url("logo@2x.png");
}
}
1dppx represents 96 CSS pixels per inch, so 2dppx is equivalent to 192dpi. The query describes resolution rather than a branded class of display and needs no vendor prefix.
For content images, responsive image markup is usually better because the browser can select an appropriate source:
<img
src="photo-800.jpg"
srcset="photo-800.jpg 1x, photo-1600.jpg 2x"
width="800"
height="450"
alt="…">
Do not use resolution as a proxy for viewport size or device category. Combine it with other conditions only when the design has an independent reason to do so.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents