What is a dp?
A density-independent pixel (dp, sometimes written dip) is Android's virtual unit for layout. One dp equals one physical pixel on a 160 dpi screen, the "medium density" (mdpi) baseline. On denser screens each dp covers more physical pixels, so a 48 dp button is roughly the same physical size on a budget phone and on a flagship.
The DP to PX formula
For example, 16 dp on a 480 dpi (xxhdpi) screen is 16 × (480 ÷ 160) = 16 × 3 = 48 px. Going the other way, a 96 px image on an xhdpi (320 dpi) screen is 96 ÷ 2 = 48 dp.
Android density buckets
Android groups screens into generalized density buckets and lets you supply bitmap resources for each one. The last column shows the pixel size of a standard 48 dp launcher icon in each bucket.
| Bucket | Approx. dpi | Scale | 48 dp icon |
|---|---|---|---|
| ldpi | 120 | 0.75× | 36 px |
| mdpi | 160 | 1× | 48 px |
| tvdpi | 213 | ≈1.33× | 64 px |
| hdpi | 240 | 1.5× | 72 px |
| xhdpi | 320 | 2× | 96 px |
| xxhdpi | 480 | 3× | 144 px |
| xxxhdpi | 640 | 4× | 192 px |
Real devices rarely match a bucket exactly. A phone with a 420 dpi screen has a scale factor of 2.625, so 16 dp becomes 42 px. Android picks bitmap resources from the closest bucket and scales them, while layout sizes in dp are converted using the device's actual density.
dp vs. sp
Use sp (scale-independent pixels) for text. An sp starts out the same as a dp, but it also scales with the user's font size setting, so text stays readable for people who enlarge it. Use dp for everything else: margins, padding, icon sizes and touch targets.
How dp compares with iOS points and CSS pixels
Other platforms use the same idea. On iOS, layouts are measured in points and rendered at @1x, @2x or @3x, so a 44 pt button is 132 px on a @3x iPhone. On the web, the CSS pixel is a reference unit, and window.devicePixelRatio tells you how many device pixels each one covers. A CSS pixel at a device pixel ratio of 3 behaves much like a dp on an xxhdpi phone.
Common sizes in dp
- 48 × 48 dp: the minimum touch target recommended by Material Design, and the size of a launcher icon.
- 24 dp: the standard Material system icon size.
- 16 dp: a common margin at the edge of a phone screen.
- 56 dp: the size of a standard floating action button.
- 8 dp: the base step of Material's spacing grid.
Frequently asked questions
How many pixels is 1 dp?
Exactly 1 px on a 160 dpi (mdpi) screen, 2 px on xhdpi, 3 px on xxhdpi and 4 px on xxxhdpi. On any other screen, multiply by the device's dpi ÷ 160.
Should I design in dp or px?
Specify layouts in dp and text in sp. Only work in px when you are exporting bitmap assets for a specific density.
How do I find my phone's density?
With the phone connected, run adb shell wm density, or read resources.displayMetrics.densityDpi in your app's code.
Related tools
- PPI calculator: find the pixel density of any screen from its resolution and size.
- Aspect ratio calculator: find the ratio of any resolution and calculate matching dimensions.