A density-independent pixel (dp) is Android’s virtual unit for specifying layout sizes and positions. Android converts dp values into physical pixels according to the display’s density, helping interface elements keep a more consistent perceived size across screens.
What does density-independent pixel mean?
Android uses density-independent pixels, commonly written as dp or dip, to describe the size and position of interface elements without tying a layout directly to a device’s raw pixel count. The unit is normalized to a baseline of 160 dots per inch (dpi): at that density, 1 dp is approximately 1 physical pixel. Android’s screen-density guidance explains this scaling model.
As an Amazon Associate I earn from qualifying purchases.
A dp is not itself a physical pixel or a fixed physical length. Android maps it to a suitable number of pixels using the display density reported by the system.
How do you convert dp to pixels?
The conversion is:
pixels = dp × (density in dpi ÷ 160)
To convert in the other direction:
dp = pixels × 160 ÷ density in dpi
For example, at 240 dpi, 1 dp maps to 1.5 pixels; at 320 dpi, 1 dp maps to 2 pixels. These are conversion examples based on Android’s 160 dpi baseline, not claims about a particular device. The Android 11 Compatibility Definition specifies the density scaling relationship.
#1 Best Overall
Why use dp for layouts?
The same number of raw pixels can take up different apparent space on displays with different pixel densities. Using dp lets Android scale layout dimensions so controls and spacing remain more consistent in perceived size across those displays. It does not make every screen physically identical or eliminate the need to adapt a layout to the available screen space.
Pixel density and resolution are related but different: density describes how tightly pixels are packed, while resolution is the display’s total pixel count. A dp-based layout addresses density scaling; it does not determine how much space a screen has for content.
Rank #2
When should you use dp, and when should you use sp?
Use dp for general layout dimensions such as margins, padding, and view sizes. Use sp for text sizes when text should respond to the user’s preferred font size, including larger accessibility settings. Sp has the same default size as dp but incorporates that user preference, so the units are not interchangeable for every purpose. See Android’s guidance on screen densities and scalable units.
Is dp the same as an iOS point or a CSS pixel?
Android design guidance describes dp as “essentially equivalent” to iOS points or CSS pixels as a practical design comparison. That is a useful analogy, not a guarantee that the units behave identically in every platform or rendering context. The term dp specifically refers to Android’s density-aware layout unit. Google’s Android design guidance describes the goal: “Measuring and sizing things in DPs ensures your designs have a consistent physical size across devices of varying density.”
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




