# Understanding Density-Independent Pixels

DevFeed: [Understanding Density-Independent Pixels](<https://devfeed.tech/articles/understanding-density-independent-pixels-38463.md>)

Original publisher: [Read original article](<https://eevis.codes/blog/2023-09-04/understanding-density-independent-pixels/>)

Author: Eevis Panula

Published: 2023-09-04T03:35:34.847000Z

Content type: tutorial

Language: en

Sources: [Eevis Blog](<https://devfeed.tech/sources/eevis-blog.md>)

Topics: [Android](<https://devfeed.tech/topics/android.md>), [android-development](<https://devfeed.tech/topics/android-development.md>), [Development](<https://devfeed.tech/topics/development.md>), [Jetpack Compose](<https://devfeed.tech/topics/jetpack-compose.md>), [Front end](<https://devfeed.tech/topics/frontend.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-development](<https://devfeed.tech/tags/android-development.md>), [development](<https://devfeed.tech/tags/development.md>), [front-end](<https://devfeed.tech/tags/front-end.md>), [jetpack-compose](<https://devfeed.tech/tags/jetpack-compose.md>), [pixel](<https://devfeed.tech/tags/pixel.md>), [screen](<https://devfeed.tech/tags/screen.md>)

## AI overview

This tutorial explains density-independent pixels (dp) in Android, why they help preserve UI sizing across screens with different pixel densities, and how Android maps dp to physical pixels. It also introduces pixel conversions in Jetpack Compose.

## Source excerpt

I switched to Android development from web front end, and one thing that was a bit hard to understand was how the density of Android screens affects the use of units. For web, I mainly worked with pixels, ems (the computed value of the element's font size), and rems (the computed value of the root element's font size). So, I wanted to write a blog post about this theme because I bet I'm not the only one. Let's first look at the density-independent pixels, what they are, and why they're used. After that, let's discuss the conversion between them and pixels. I've purposely omitted scale-independent pixels from this blog post to concentrate on density-independent pixels. What Are Density-Independent Pixels? Android devices have different sizes of screens. They also have different pixel sizes for a screen - so a certain amount of pixels in, e.g., width, looks different on a screen with fewer pixels compared to one with a lot more pixels. This is because one screen might fit only 320 pixels in the same physical space while the other fits 640 pixels. Density-independent pixels are here to fix the issues these differences cause. Android documentation defines density-independent pixels in the following way: To preserve the visible size of your UI on screens with different densities, design your UI using density-independent pixels (dp) as your unit of measurement. One dp is a virtual pixel unit that's roughly equal to one pixel on a medium-density screen (160 dpi, or the "baseline" density). Android translates this value to the appropriate number of real pixels for each other density. Source: Support different pixel densities - Android Developers Let's next look at the conversions between real pixels and density-independent pixels. Conversions Between Pixels and Density-Independent Pixels There are multiple cases when we need the conversion from device-independent pixels to pixels - and vice versa. Let's look at how we can convert them - first in the scope of Composable comp