Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Media Queries and Features

The resolution media feature

Reference for the CSS resolution media feature: query pixel density in dpi, dppx or x units, pick sharper images for high-density screens, with examples.

The resolution media feature tests the pixel density of the output device: how many device pixels are packed into one CSS pixel (or into an inch, or centimeter). A standard desktop monitor is around 1dppx; many phones and laptops are 2dppx or higher. It supports the range syntax and the min- and max- prefixes.

The classic use is choosing a sharper background image on dense screens.

CSS
@media (resolution >= 2dppx) {
  .logo {
    background-image: url("[email protected]");
  }
}

Try it

The label reports which density bucket your preview falls into. Zooming the browser also changes the device pixel ratio, so try zooming in and out.

Density buckets

Syntax

CSS
@media (resolution: 2dppx) { /* exactly 2 */ }
@media (min-resolution: 192dpi) { /* at least */ }
@media (max-resolution: 1.5x) { /* at most */ }
@media (resolution >= 2dppx) { /* range syntax */ }
@media (resolution: infinite) { /* vector output, such as some printers */ }

It is a range media feature, accepting a resolution value.

Values

Value Description
<number>dpi Dots per inch.
<number>dpcm Dots per centimeter.
<number>dppx Dots per CSS pixel; 1dppx equals 96dpi.
<number>x An alias for dppx.
infinite Output with effectively unlimited resolution.

Usage notes

  • Use dppx or x. They match what developers think about (device pixels per CSS pixel). Use dpi only when you target print.
  • Prefer srcset for content images. For images in the document, <img srcset> and <picture> let the browser choose and download only one file. A resolution query is best for CSS background images.
  • Browser zoom changes it. Zooming in raises the device pixel ratio, so the query can match when the user zooms even on a standard screen.
  • Avoid exact matches. Densities like 1.25 or 1.75 exist. Prefer >= thresholds over resolution: 2dppx.
  • Old prefixed forms. Legacy code uses -webkit-min-device-pixel-ratio. Modern browsers support min-resolution, so you rarely need the prefix.
  • Vector assets. SVG backgrounds are crisp at any density, so they need no resolution query.

Browser support

The unprefixed resolution feature and its dppx and x units are supported by current major browsers; check a compatibility table for very old versions.