Device-independent pixel

Device-dependent pixel
Unit systemComputer-related unit of measurement; not an SI unit.
Unit ofLength
Symboldp, dip
Named afterPixel
Conversions
1 dp, dip in ...... is equal to ...
   Inch   1160 inch (0.16 mm)[1]
   Pixel   1 px on 160 dpi screen[a]
Open visual editor for coding an Android mobile app. It emulates a visual representation of the app on a phone. Black phone with a white screen containing multi-coloured horizontal bars which form a bar chart used to compare all units for measuring screen dimensions, which differ in how they relate to the physical size of the display. The virtual units are a device-dependant pixel (dp) and pixels (px); and physical units which are millimetres (mm) and points (pt). First bar is red and is labeled 1 inch, it's the second longest, half the length of the green bar which is second and is 50 millimetres. The third blue bar which represents 100 device-dependant pixels, is one-third the length of 50 mm and approx. Over half the length of 1 inch. The fourth pink bar is also the shortest and measures 30 points and is half the length of the last bar that follows. Lastly the fifth yellow bar is 200 pixels long and is approx. the same length as the blue 100 device-dependant pixel bar which is one-third 50mm and over half 1 inch.
Bar chart length comparison of the virtual units of length, 100 device-dependant pixels (dp) and 200 pixels (px); and physical units of length, 50 millimetres (mm) and 30 points (pt).

A device-independent pixel (also: density-independent pixel, dip, dp) is a unit of length.

A typical use is to allow mobile device software to scale the display of information and user interaction to different screen sizes. The abstraction allows an application to work in pixels as a measurement, while the underlying graphics system converts the abstract pixel measurements of the application into real pixel measurements appropriate to the particular device. For example, on the Android operating system a device-independent pixel is equivalent to one physical pixel on a 160 dpi screen,[2] while the Windows Presentation Foundation specifies one device-independent pixel as equivalent to 1/96th of an inch.[3]

As dp is a physical unit it has an absolute value which can be measured in traditional units, e.g. for Android devices 1 dp equals 1/160 of inch or 0.15875 mm.

While traditional pixels only refer to the display of information, device-independent pixels may also be used to measure user input such as input on a touch screen device.

Bar chart comparing 200 dp, 100 px, 50 mm and 50 pt

200 dp
calc: 200 × 0.6px = 120px (computed)
100 px
100 px
50 mm
50 mm (CSS)
50 pt
50 pt (CSS)

Notes

[edit]

References

[edit]
  1. ^ "CSS Values and Units Module Level 3". www.w3.org.
  2. ^ "Support different pixel densities". Android for Developers. Google. Retrieved 30 March 2023.
  3. ^ Samer; Chipalo. "WPF Text Measurement Units". MSDN Blogs. Microsoft. Archived from the original on 4 March 2016.