What is Pixel Density and Why Should You Care?

by

Pixel density is the number of pixels per linear physical unit. Measured in pixels per inch (ppi or dpi). Pixel density and resolution are technically the same thing, but often people say “resolution” to mean “pixel count,” a related metric:

count = densityH * width * densityV * height

When other things are held constant:

Small pixels ~ more pixels ~ high density ~ high resolution
Large pixels ~ fewer pixels ~ low density ~ low resolution

Usually pixels are square, so the vertical and horizontal density are the same.

A 200×600 pixel image displayed on two same-physical-size screens is physically smaller on the higher resolution screen.

It started with the iPhone

  • Before Retina, typical screens were 160 dpi.
  • With Retina, dpi doubled.
  • Designers export graphics in two formats, since a 44px button on a non-Retina (1x) display needed to be 88px to be the same physical size on a Retina display (2x).
  • 1x & 2x are pixel density ratios.
  • Users are spoiled by 2x.
  • We can no longer use pixels as a universal unit of measurement—a 7px margin means different things on different screens.
  • New unit in iOS is points (pt) where:
    • for 1x,1 pt = 1px
    • for 2x, 1pt = 2px
    • for 3x, 1pt = 3px
  • For a given device screen:
    • [pixels] = [points] * [pixel density ratio]
    • Designing at 1x is convenient

Notes & Complications

  • Android uses density-indepent pixels (dip or dp) instead of points (pt). Better name for the exact same idea.
  • Android has 1x mdpi, 1.5x hdpi, 2x xhdpi, 3x xxhdpi, 4x xxxhdpi, as well as ldpi and tvdpi but those are rare.
  • Note: For both Android and iOS, pixel density ratios aren’t always exact, so e.g. 3x is a category of close ratios.
  • Physical screen size, viewing distance, mouse vs touch.
  • Will there be more densities in the future?

How to avoid blurriness

  • When possible, use vectors.
  • Vectors be exported at any density without blurriness.
  • One day we’ll be able to use vectors directly without rasterizing.
  • When possible, draw simple shapes programmatically.

Why should devs care about pixels?

  • Many APIs still deal in units of pixels, so your application will need to convert dips or points to and from pixels.
    • setTranslation, setScale, setMatrix
  • This will likely be the case for a long time, since dips and points are convenient framework concepts, but we can’t totally get away from pixels because they’re still the framework-agnostic fundamental unit of computer graphics.

Resources

  1. Pixel Density, Demystified (video)
  2. Design at 1x—It’s a Fact
  3. Device Metrics
  4. Density Converter
  5. Units and Measurement – Material Design Guidelines
  6. Designer’s guide to DPI
  7. Points Versus Pixels – iOS Drawing Concepts
  8. Supporting Different Densities – Android Developers

Leave a Reply

Your email address will not be published. Required fields are marked *