Course contentsShow
← Web Development
Lesson 379 of 2,9827. Responsive DesignFree lesson

Device Pixels vs CSS Pixels

How physical screen pixels differ from CSS pixels and the role of device pixel ratio in modern displays.

Device Pixels vs CSS Pixels

What you'll learn: How the pixels you write in CSS differ from the actual physical pixels on a screen, and why this matters for responsive design.

When you started learning CSS, you probably assumed that width: 100px means exactly 100 tiny dots on your screen. Surprisingly, that's not quite true!

Physical Device Pixels

Device pixels (also called physical pixels or hardware pixels) are the actual tiny lights built into your screen. An iPhone might have 750 device pixels across its width, while a desktop monitor might have 1920.

CSS Pixels: A Reference Unit

CSS pixels are abstract reference units that browsers use for consistent sizing. When you write width: 100px, you're using CSS pixels, not device pixels. Think of CSS pixels like standardized "measuring cups" in a recipe—they stay the same size conceptually, even if the actual cups vary slightly.

The Device Pixel Ratio

The device pixel ratio (DPR) is the bridge between these two worlds. It tells you how many device pixels equal one CSS pixel.

  • DPR of 1: 1 CSS pixel = 1 device pixel (older displays)
  • DPR of 2: 1 CSS pixel = 4 device pixels (2×2 grid) — common on modern phones
  • DPR of 3: 1 CSS pixel = 9 device pixels (3×3 grid) — high-end displays

An iPhone with 750 device pixels wide and DPR of 2 reports a width of 375 CSS pixels (750 ÷ 2). This is why your width: 375px element fits perfectly edge-to-edge.

This system exists so that text and buttons appear roughly the same physical size across devices, even as screens pack in more and more pixels for sharper images.

Key Takeaway: CSS pixels are abstract units that stay consistent across devices, while device pixels are the physical lights on screen—the device pixel ratio determines how many hardware pixels render each CSS pixel.