Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Units and Values

The resolution units: dpi, dpcm, dppx and x

Reference for CSS resolution units dpi, dpcm, dppx and x: how they relate, where they are allowed, and how to use them in media queries and image-set().

Resolution units describe pixel density: how many device pixels are used to draw a given amount of space. CSS has four of them: dpi (dots per inch), dpcm (dots per centimeter), dppx (dots per CSS pixel) and x, which is simply another spelling of dppx.

A value with a resolution unit is a <resolution>. It is not a length, so you cannot use it for width or margin. It appears in just two places: the resolution media feature, and image-set() for choosing between image files.

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

Try it

Read the screen density

Syntax

CSS
<resolution> = <number> [ dpi | dpcm | dppx | x ]

Conversion factors:

Unit Equals
1dppx 1 device pixel per CSS pixel
1x 1dppx
1dpi 1/96 dppx
1dpcm about 2.54 dpi (1 inch is 2.54 cm)
96dpi 1dppx

Values

Value Description
dpi Dots per inch. 96dpi is the same as 1dppx.
dpcm Dots per centimeter. 1dpcm is about 2.54dpi.
dppx Dots per CSS pixel. A "2x" display has 2dppx.
x Alias for dppx. Common in image-set(), for example url([email protected]) 2x.

Usage notes

  • Prefer dppx or x. They match what JavaScript reports as window.devicePixelRatio, so the numbers in your CSS and script agree.
  • dpi is not physical. Browsers define 96dpi as one CSS pixel per device pixel. The unit does not measure real printed dots unless you are printing.
  • Use min-resolution for high-density rules. A min- query with 2dppx matches every display at 2x or above, so one rule covers 2x, 3x and beyond.
  • Often unnecessary. Modern pages can use srcset in HTML, or image-set() in CSS, and let the browser pick the file. Write your own resolution queries only when you need different layout or styles per density.
  • Not valid elsewhere. width: 2dppx is invalid and ignored.

Browser support

dppx, dpi and dpcm have long been supported; the x spelling is newer, so check a compatibility table before using it in a media query without a fallback.