dp vs px vs sp in Android: The Simple Explanation

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.

Free tool
Convert dp to px
Convert dp, sp and px for every density – mdpi to xxxhdpi – and get pixel sizes for icons and drawables. Free.
Open dp to px Converter →

The three units

UnitNameUse it for
pxPixelsAlmost never in layouts – only for exact bitmap sizes
dpDensity-independent pixelsWidths, heights, margins, padding, icons
spScale-independent pixelsText 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

BucketdpiScale48 dp equals
ldpi1200.75×36 px
mdpi1601×48 px
hdpi2401.5×72 px
xhdpi3202×96 px
xxhdpi4803×144 px
xxxhdpi6404×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" and android:textSize="16sp"
  • Jetpack Compose: Modifier.size(48.dp) and fontSize = 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.

Free tool
Try the free dp to px Converter
No signup and nothing uploaded – it runs right in your browser. Browse all 74 free tools on our Free Tools page.
Open dp to px Converter →

Need help building or publishing your app? Talk to Techpass Master – we design, build and publish Android apps for clients worldwide.

WhatsApp us📞 Call now