px — a physical pixel, the smallest element of an image on a device screen. In mobile development, px is used as the basic unit of screen resolution and pixel density (PPI), but is practically never used for interface layout — instead, logical units pt, dp and sp are used. This article explains how px differs from logical units, how resolution and PPI are related, and why directly using px in code is an anti-pattern.
Key Takeaways
px (pixel, picture element) — the smallest addressable element of a raster image or display. Each pixel stores color information in the RGB model (red, green, blue) with a color depth of 8 to 10 bits per channel. Modern mobile device displays contain millions of pixels: iPhone 15 Pro — 3 million, iPad Pro 12.9" — 5.6 million pixels.
The physical size of a pixel depends on the display density (PPI). On a device with 326 PPI (iPhone 11), one pixel is approximately 0.078 mm. On a display with 460 PPI (iPhone 15 Pro) — 0.055 mm. The smaller the physical pixel size, the higher the sharpness of the image. At the same time, pixel density directly affects rendering performance: more pixels = more work for the GPU.
According to Apple, the iPhone 15 Pro display resolution is 1179 × 2556 px at 460 PPI. For comparison, the iPhone SE (3rd gen) — 750 × 1334 px at 326 PPI. The difference in total pixel count is almost 3 times, which explains the higher GPU requirements on Pro models.
Screen resolution — the number of physical pixels horizontally and vertically. It is written in the format width × height, for example 1179 × 2556 px. Resolution is a fundamental characteristic of the display that cannot be changed programmatically — it is fixed at the hardware and matrix level.
| Device | Resolution (px) | PPI | Aspect Ratio |
|---|---|---|---|
| iPhone SE (3rd gen) | 750 × 1334 | 326 | 16:9 |
| iPhone 14 | 1170 × 2532 | 460 | 19.5:9 |
| iPhone 15 Pro Max | 1290 × 2796 | 460 | 19.5:9 |
| Samsung Galaxy S24 Ultra | 1440 × 3120 | 505 | 19.5:9 |
| Google Pixel 8 Pro | 1344 × 2992 | 490 | 20:9 |
| iPad Pro 12.9" | 2048 × 2732 | 264 | 4:3 |
Resolution in pixels should not be confused with the logical screen size (in pt for iOS or dp for Android). For example, the iPhone 14 has a logical size of 390 × 844 pt, but a physical resolution of 1170 × 2532 px — exactly 3 times larger, since the scale factor is 3.
PPI (pixels per inch) — the number of pixels per inch of the display. Calculated by the formula: PPI = √(width² + height²) / diagonal. The higher the PPI, the smaller the individual pixels and the smoother the image appears. Apple considers a Retina display to have a PPI above 300 at a typical viewing distance.
Different device categories have different densities: Apple Watch — 326 PPI, iPhone — 326–460 PPI, iPad — 264 PPI, MacBook Pro — 254–264 PPI. Android devices classify density using Density Buckets: mdpi (160 dpi), hdpi (240), xhdpi (320), xxhdpi (480), xxxhdpi (640). These buckets determine which resource (image, dimens) will be loaded for the device.
Impact of PPI on development: the higher the density, the more memory is required to store textures and images. A pixel on a 500 PPI display requires 2.5 times more GPU memory than a 320 PPI display for the same logical element size. Optimizing assets for specific density buckets is a standard practice in Android development.
Physical pixels (px) differ from logical units (pt, dp, sp) in that they are tied to hardware resolution and do not scale. Logical units, on the contrary, abstract the developer from the specific display, allowing a single value of 100 pt to display with the same physical size on different devices.
| Unit | Platform | Depends on PPI | Scales | Purpose |
|---|---|---|---|---|
| px | All | Yes (physical pixel) | No | Images, buffers, Metal |
| pt | iOS/macOS | No (logical point) | scale factor | Layout, UIKit, SwiftUI |
| dp | Android | No (density-independent) | density bucket | Layout, element sizes |
| sp | Android | No (scale-independent) | density + font scale | Text (textSize) |
Conversion formulas: for iOS — px = pt × scale (where scale = 1, 2 or 3). For Android — px = dp × (dpi / 160). Direct use of px in code means the interface will look different on devices with different densities: on a high PPI screen the element will be too small, and on a low PPI screen — too large.
Using px in the source code of a mobile application is an anti-pattern that leads to incorrect interface display on devices with different pixel densities. Modern frameworks (UIKit, SwiftUI, Jetpack Compose, XML Layouts) prohibit or do not recommend specifying sizes in pixels.
The only legitimate use of px in code is working with rasters: loading Bitmap, creating Canvas for image rendering, working with Metal or OpenGL. In these cases, px are the physical pixels of the target buffer, and they must be taken into account for correct rendering. In all other cases, logical units are used.
Images and icons are stored in pixels, but different versions are supplied for each screen type. iOS uses @1x, @2x, @3x suffixes in Assets.xcassets. Android uses drawable-mdpi (1×), drawable-hdpi (1.5×), drawable-xhdpi (2×), drawable-xxhdpi (3×), drawable-xxxhdpi (4×) folders. The system automatically selects the correct file based on screen density.
| iOS scale | Android bucket | Factor | Example (48 pt/dp) |
|---|---|---|---|
| @1x | mdpi (160 dpi) | 1× | 48 × 48 px |
| @2x | xhdpi (320 dpi) | 2× | 96 × 96 px |
| @3x | xxhdpi (480 dpi) | 3× | 144 × 144 px |
| — | xxxhdpi (640 dpi) | 4× | 192 × 192 px |
Asset delivery rule: create the image in vector format (PDF, SVG) and export to raster copies of the required sizes. Vector assets scale without quality loss and take up less space in the repository. In Android, vector resources can be used directly through VectorDrawable, eliminating the need for multiple raster copies.
Frequently Asked Questions
px — a physical screen pixel. dp (density-independent pixel) — a logical Android unit equal to 1 px on a screen with 160 dpi density. At different densities, dp automatically converts to a different number of px, preserving the physical size of the element.
Because px does not account for screen density. A 100 px element will look different on devices with different PPI: on a 326 PPI screen it will be larger than on 460 PPI. Logical units (dp, pt, sp) solve this problem automatically.
PPI (pixels per inch) — the number of pixels per inch of the display. Calculated by the formula: PPI = √(w² + h²) / d, where w and h are the resolution in px, d is the diagonal in inches. The higher the PPI, the sharper the image. Apple Retina display starts at 300 PPI.
px is justified when working with raster buffers: creating Bitmap, rendering in Canvas, programming Metal/OpenGL shaders, processing images from the camera. In layout and typography, px is not used — pt (iOS), dp and sp (Android) are applied.
In iOS: UIScreen.main.nativeBounds returns the size in px. In Android: DisplayMetrics.widthPixels and heightPixels from context.resources.displayMetrics. In SwiftUI: GeometryReader returns the size in pt, for px you need to multiply by displayScale.
Summary
We will develop a mobile application turnkey
IT Sectr creates iOS and Android applications for startups and businesses since 2017. We will advise you and propose the best solution.
Read also