Appearance
Android dp, px and sp converter
In short: The Android dp to px converter turns dp, px or sp into the other units for any screen density, using Android's formula px = dp × dpi / 160, and shows the value in every bucket from ldpi to xxxhdpi. It also finds a screen's size in dp, its smallest width and window size class, and launcher icon sizes, all in your browser.
Result
16 dp = 42 px at 420 dpi; a dimension resource gets 42 px| Bucket | dpi | Density | Exact px | Pixel size |
|---|---|---|---|---|
| ldpi | 120 | 0.75 | 12 | 12 |
| mdpi | 160 | 1 | 16 | 16 |
| tvdpi | 213 | 1.3313 | 21.3 | 21 |
| hdpi | 240 | 1.5 | 24 | 24 |
| xhdpi | 320 | 2 | 32 | 32 |
| xxhdpi | 480 | 3 | 48 | 48 |
| xxxhdpi | 640 | 4 | 64 | 64 |
A screen’s size in dp
- Size in dp
- 411.4 × 914.3 dp
- Smallest width
- 411 dp (picks resources up to
values-sw411dp) - Density bucket
- xxhdpi (resources picked from the closest bucket at or above 420 dpi)
- Window size class
- compact width, expanded height (full screen, as entered)
Launcher icon sizes
| mipmap-ldpi | mipmap-mdpi | mipmap-hdpi | mipmap-xhdpi | mipmap-xxhdpi | mipmap-xxxhdpi |
|---|---|---|---|---|---|
| 36 × 36 px | 48 × 48 px | 72 × 72 px | 96 × 96 px | 144 × 144 px | 192 × 192 px |
Everything here is arithmetic in your browser: nothing is sent anywhere.
Checking a layout at large font sizes on several phones? On Pro, BenchFleet's workflows set a test phone's font size, dark mode, language and animations for a run and put them back when it ends, on many phones at once, with screenshots of each run. See workflows and schedules.
Free for up to 3 phones, with no account. Pro adds workflows, schedules and AI for up to 25 phones from £12 a month + VAT.
The formula
Android defines one dp as one pixel on a 160 dpi screen, its baseline (mdpi):
px = dp × (dpi / 160) and dp = px × 160 / dpi
dpi / 160 is the screen's density, DisplayMetrics.density: 1 on mdpi, 1.5 on hdpi, 2 on xhdpi, 3 on xxhdpi and 4 on xxxhdpi. sp is dp multiplied by the person's font scale. Android 14 and newer scale large text less than that above 100% (non-linear font scaling), so for big text the real size can be smaller than the linear value.
In code, let Android convert: TypedValue.applyDimension for dp and sp, or a dimension resource with getDimensionPixelSize. Android's guide to screen pixel densities has the details.
Density buckets
| Bucket | dpi | Density | 48dp is |
|---|---|---|---|
| ldpi | 120 | 0.75 | 36 px |
| mdpi | 160 | 1 | 48 px |
| tvdpi | about 213 | about 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 |
Bitmaps follow the 3:4:6:8:12:16 ratio between the six main buckets. Put launcher icons in mipmap- folders, since some launchers show icons larger than the phone's own bucket.
Examples
- A 16dp margin on a 1080 × 2400 phone at 420 dpi is 16 × 420 / 160 = 42 px.
- A 1080 × 2400 screen at 420 dpi is about 411 × 914 dp: a compact width in portrait. The whole screen is just over the 900dp line for an expanded height, though an app's window, without the system bars, is usually shorter. Its smallest width, 411dp, picks resources up to
values-sw411dp. - A 48dp launcher icon needs 48, 72, 96, 144 and 192 pixel squares from mdpi to xxxhdpi; an adaptive icon's 108dp layers need 108 to 432 pixels.
Check a real phone
bash
adb shell wm density
adb shell wm sizewm density prints the screen's physical density and any override; wm size its size in pixels. To see a layout at another density, adb shell wm density 480 overrides it.
Careful: a density override stays until you remove it, on many phones even after a restart. Put it back with
adb shell wm density reset.
The ADB command builder writes these and other commands for one phone or every phone.
Large text, display size and dark mode are in the screen settings of the mobile app testing checklist.
Questions
How do I convert dp to px?
Multiply by the screen's density in dpi divided by 160, Android's baseline. 16dp on a 420 dpi screen is 16 × 420 / 160 = 42 px; on xxhdpi (480 dpi) it is 48 px.
What is the difference between dp and sp?
Both are density-independent and equal by default. sp also grows with the person's font size setting, so use sp for text and dp for everything else.
Why does Android round some sizes differently?
A dimension resource becomes whole pixels when it is used as a size, rounded to the nearest pixel and never 0 for a size that is not 0. The converter shows both the exact value and that pixel size.
Which density bucket is my phone?
Read its density with adb shell wm density. Android picks resources from the closest bucket at or above it, so a 420 dpi phone uses xxhdpi resources, scaled down.
What are window size classes?
Android's breakpoints for adaptive layouts, by available width. Compact under 600dp, medium under 840dp, expanded under 1200dp, large under 1600dp and extra-large above. They follow the app's window, not the device.
Start with the Free plan
Free for up to 3 phones, with no account. Pro adds workflows, schedules and AI for up to 25 phones from £12 a month + VAT.
- A Free plan with no time limit and no account
- Starts in Local mode, with no telemetry or analytics in the app