Android phones come with very different screen densities. A button that is 48 pixels tall looks fine on an old phone and tiny on a modern one. That is why Android uses density-independent units – dp for sizes and sp for text. Here is what each unit means and how to convert between them.
Page Contents
The three units
| Unit | Name | Use it for |
|---|---|---|
| px | Pixels | Almost never in layouts – only for exact bitmap sizes |
| dp | Density-independent pixels | Widths, heights, margins, padding, icons |
| sp | Scale-independent pixels | Text sizes |
The formula
px = dp × (dpi ÷ 160)
160 dpi (mdpi) is the baseline, where 1 dp = 1 px. On a 480 dpi (xxhdpi) screen, 1 dp = 3 px, so a 48 dp button is 144 px tall.
Density buckets
| Bucket | dpi | Scale | 48 dp equals |
|---|---|---|---|
| ldpi | 120 | 0.75× | 36 px |
| mdpi | 160 | 1× | 48 px |
| hdpi | 240 | 1.5× | 72 px |
| xhdpi | 320 | 2× | 96 px |
| xxhdpi | 480 | 3× | 144 px |
| xxxhdpi | 640 | 4× | 192 px |
Use our dp to px Converter to convert any value instantly.
Why sp for text?
sp works like dp but also follows the user’s font size setting. If someone increases text size for accessibility, text in sp grows while your layout in dp stays the same. Using dp for text ignores that setting and makes your app harder to use for many people.
Design tip: test your layouts with the largest font size – text in sp can overflow fixed-height containers.
In code
- XML:
android:layout_width="48dp"andandroid:textSize="16sp" - Jetpack Compose:
Modifier.size(48.dp)andfontSize = 16.sp - Convert in Kotlin (View system):
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 48f, resources.displayMetrics) - Compose:
with(LocalDensity.current) { 48.dp.toPx() }
Useful sizes to remember
- Minimum touch target: 48 × 48 dp (Material Design and accessibility guidelines)
- Launcher icon layers: 108 × 108 dp – see our adaptive icons guide
- Toolbar height: 56 dp on phones (Material)
- Body text: 14–16 sp
Designers: Figma and dp
Design at 1× (a 360 × 800 dp frame is a common Android phone size) and treat Figma pixels as dp. Developers can then use the same numbers in code.
FAQ
How many pixels is 1 dp?
It depends on the screen density: 1 px on mdpi, 2 px on xhdpi, 3 px on xxhdpi, 4 px on xxxhdpi.
What is the difference between dp and sp?
Both scale with screen density; sp also scales with the user’s font-size setting. Use sp for text.
Is dp the same as pt in iOS?
They are similar ideas. iOS points are density-independent too, with @2x and @3x scales.
Should I ever use px?
Rarely – for example for exact bitmap sizes or 1-pixel dividers.
What dpi is my phone?
Most modern phones are xxhdpi (around 480 dpi) or xxxhdpi.
Need help building or publishing your app? Talk to Techpass Master – we design, build and publish Android apps for clients worldwide.
