Device pixel ratio (DPR) is the number of physical screen pixels used to draw one CSS pixel, in each direction. On a DPR 3 phone, every CSS pixel is drawn with a 3 × 3 block of device pixels. That’s why a 360 px-wide website can fill a phone screen that’s 1080 hardware pixels across. You can check yours with window.devicePixelRatio in the browser console.

CSS pixels vs device pixels

CSS pixel Device pixel
Also called Logical pixel, point (iOS), dp (Android) Physical pixel, hardware pixel
Used by CSS, JavaScript, design tools The screen hardware
Size Nominally 1/96 inch; varies in practice Fixed by the panel’s PPI
Changes with zoom? Yes No

Web layouts are written in CSS pixels so that a 16 px font is readable on every device. The browser multiplies by the DPR to decide how many device pixels to light up.

The formula: device pixels = CSS pixels × DPR. A 393 CSS px wide iPhone at DPR 3 has 393 × 3 = 1179 device pixels across.

Typical device pixel ratios

Device DPR CSS width Device pixels across
iPhone 15 / 15 Pro 3 393 px 1179
iPhone 15 Pro Max 3 430 px 1290
iPhone SE (3rd gen) 2 375 px 750
Pixel 8 2.625 412 px 1080
Galaxy S24 3 360 px (default) 1080
iPad (10th gen) 2 820 px 1640
MacBook Air (Retina) 2 1470 px (default) 2940 (scaled)
1080p office monitor 1 1920 px 1920
4K monitor at 150% Windows scaling 1.5 2560 px 3840

Values vary with display-size settings. Many Android phones let you change DPR in Settings → Display size: a larger display size means a higher DPR and fewer CSS pixels across.

iPhone device pixel ratio by model

Apple calls DPR the scale factor: @2x or @3x. Safari reports it as window.devicePixelRatio. Values below come from Apple’s published resolutions and point sizes (portrait).

iPhone Scale (DPR) CSS viewport (points) Device pixels PPI
iPhone XR, 11 2 414 × 896 828 × 1792 326
iPhone SE (2nd and 3rd gen) 2 375 × 667 750 × 1334 326
iPhone 12 mini, 13 mini 3 375 × 812 1080 × 2340 476
iPhone 12, 12 Pro, 13, 13 Pro, 14 3 390 × 844 1170 × 2532 460
iPhone 12 Pro Max, 13 Pro Max, 14 Plus 3 428 × 926 1284 × 2778 458
iPhone 15, 15 Pro 3 393 × 852 1179 × 2556 460
iPhone 15 Pro Max 3 430 × 932 1290 × 2796 460

The iPhone 12 mini shows why DPR and PPI aren’t the same thing. It has the highest PPI in the list, but the same DPR of 3 as the larger models, so its CSS pixels are physically smaller: 476 ÷ 3 ≈ 159 CSS px per inch, against 153 on an iPhone 15.

Apple calls CSS pixels “points”: its @2x and @3x image assets are the same idea as DPR 2 and 3.

Android: dp, density buckets and DPR

Android measures layout in density-independent pixels (dp). Android’s documentation defines 1 dp as one physical pixel on a 160 dpi “baseline” screen, so px = dp × (dpi ÷ 160). That ratio is the same number Chrome reports as devicePixelRatio.

Android density bucket Approx. dpi Scale (= DPR)
ldpi 120 0.75
mdpi (baseline) 160 1
hdpi 240 1.5
xhdpi 320 2
xxhdpi 480 3
xxxhdpi 640 4

Real phones rarely land exactly on a bucket. The Pixel 8’s DPR of 2.625 is a logical density of 420 dpi ÷ 160. Its 1080 px screen width divided by 2.625 is 411.4, which Chrome rounds to a 412 CSS px viewport. The density is a software setting, which is why “Display size” can change it, and fractional DPRs like this are why some layouts get 1-pixel seams or slightly soft borders on Android.

Formula: px = dp × (dpi ÷ 160). A 48 dp touch target on a 420 dpi phone is 48 × 2.625 = 126 device pixels.

Device pixel ratio vs PPI

The two are linked but not the same:

PPI Device pixel ratio
What it measures Physical pixels in one real inch Physical pixels per CSS pixel
Set by The screen hardware The operating system and browser
Can change? No Yes: zoom, scaling, display-size settings
Units Pixels per inch A plain ratio (dppx)

Two phones can share DPR 3 with very different PPI (the iPhone 12 mini at 476 PPI and the Samsung Galaxy S24 at 416 PPI, both DPR 3 at default settings), so their CSS pixels are different physical sizes. Only both numbers together tell you how big a CSS pixel really is. For the PPI side, read what is PPI.

How to check your device pixel ratio

Four ways, from simplest to most flexible:

  1. Browser console. Open DevTools (F12 on desktop, or remote debugging for phones) and type:

    window.devicePixelRatio
  2. CSS media queries. Target high-density screens in a stylesheet:

    @media (min-resolution: 2dppx) {
      /* styles for DPR 2 and above */
    }

    dppx means “dots per CSS pixel,” which is the same thing as DPR. Older Safari versions need -webkit-min-device-pixel-ratio: 2.

  3. Screen size check. screen.width is in CSS pixels. Multiply by devicePixelRatio to estimate the hardware width: 393 × 3 = 1179 on an iPhone 15. Some Android browsers round, so expect small differences.

  4. Watch for changes. DPR changes when the user zooms or drags the window to another monitor. Listen for it with matchMedia:

    function watchDpr(onChange) {
      const mq = matchMedia(`(resolution: ${devicePixelRatio}dppx)`);
      mq.addEventListener('change', () => { onChange(devicePixelRatio); watchDpr(onChange); }, { once: true });
    }

What changes the DPR

Cause Effect on devicePixelRatio
The device’s default setting Chosen by the maker (2, 2.625, 3 …)
Android “Display size” setting Larger text and UI = higher DPR
Windows display scaling 100% → 1, 125% → 1.25, 150% → 1.5, 200% → 2
macOS “Looks like” resolution Reported DPR stays 2; macOS renders larger and scales down
Desktop browser zoom Multiplies the DPR: 110% zoom on DPR 2 reports 2.2
Pinch-zoom on a phone Usually no change (it’s a visual zoom, not a layout zoom)
Moving the window to another monitor DPR switches to that monitor’s value

Why the 1/96 inch rule fails

The CSS spec defines 1 inch = 96 CSS pixels. If devices followed that physically, a 393 px iPhone would be 4.1 inches wide. It’s actually about 2.6 inches (1179 hardware pixels ÷ 460 PPI). Phone makers choose a DPR that keeps text comfortable at arm’s length, not one that keeps CSS inches accurate.

The CSS spec allows this on purpose. It defines the CSS pixel as a “reference pixel” based on viewing angle, so a phone held close can use a smaller physical pixel than a TV across the room.

So 1in in CSS is rarely a real inch. This is the main reason an uncalibrated online ruler shows the wrong size. See why online rulers are inaccurate and What is PPI?

How to calculate a CSS pixel’s real size

Physical PPI ÷ DPR = CSS pixels per inch

Example: iPhone 15 Pro at 460 PPI ÷ 3 ≈ 153 CSS px per inch. That’s about 1.6 times the 96 px a naive ruler would assume. One CSS pixel is 25.4 ÷ 153 ≈ 0.17 mm.

Device Physical PPI ÷ DPR CSS px per inch One CSS pixel is
iPhone 15 460 ÷ 3 ≈ 153 0.17 mm
Pixel 8 428 ÷ 2.625 ≈ 163 0.16 mm
iPad (10th gen) 264 ÷ 2 132 0.19 mm
24” 1080p monitor 92 ÷ 1 92 0.28 mm

Calibrating with a credit card measures this number directly, including any OS scaling. That’s how ruleronphone shows real millimeters on any device. Follow the steps on the calibration page.

Designing for DPR: images, canvas and borders

Sharp images with srcset

To look sharp, an image needs as many source pixels as device pixels. A 300 × 200 CSS px slot on a DPR 3 screen needs a 900 × 600 image. Let the browser choose:

<img src="photo-300.jpg"
     srcset="photo-300.jpg 1x, photo-600.jpg 2x, photo-900.jpg 3x"
     width="300" height="200" alt="…">

Going beyond 2× gives smaller visual gains for a lot more data, so many sites stop at 2×.

Sharp drawing on canvas

A <canvas> sized in CSS pixels looks blurry on high-DPR screens. Scale its backing store:

const dpr = window.devicePixelRatio || 1;
canvas.width = cssWidth * dpr;
canvas.height = cssHeight * dpr;
canvas.style.width = cssWidth + 'px';
canvas.style.height = cssHeight + 'px';
ctx.scale(dpr, dpr);

This is how a ruler or chart keeps its tick lines crisp.

Hairline borders

On a DPR 2 or 3 screen, border: 1px is 2–3 device pixels thick. For a single-device-pixel line, some designs use 0.5px borders on DPR 2 screens. Browsers round fractional pixels differently, so test on real devices.

What DPR means for measuring

  • Use CSS pixels for UI work. A pixel ruler that reads CSS pixels matches your code on every device.
  • Divide screenshots by DPR. A screenshot from a 3× phone is three times larger in pixels than the CSS layout. A 48 px gap in the screenshot is 16 CSS px.
  • Watch zoom. Browser zoom changes the DPR the page sees. 110% zoom on a DPR 2 screen reports 2.2.
  • Images need 2–3× resolution. To look sharp on a DPR 3 screen, a 100 px image slot needs a 300 px source image.
  • Use real units only after calibration. To measure physical objects, calibrate first. Measuring images and layouts on screen is covered in on screen ruler.

Screenshot conversion table

Screenshot pixels At DPR 1 At DPR 2 At DPR 3
48 px 48 CSS px 24 CSS px 16 CSS px
96 px 96 CSS px 48 CSS px 32 CSS px
1179 px wide 1179 CSS px 590 CSS px 393 CSS px

How to find your screen’s physical resolution from the browser

JavaScript exposes CSS sizes, so multiply by DPR to get hardware pixels:

const physicalWidth  = Math.round(screen.width  * devicePixelRatio);
const physicalHeight = Math.round(screen.height * devicePixelRatio);
Property What it returns
screen.width / screen.height Screen size in CSS pixels
window.innerWidth Layout viewport width in CSS pixels, including scrollbar
document.documentElement.clientWidth Viewport width excluding scrollbar
window.visualViewport.scale Pinch-zoom level on phones
window.devicePixelRatio Device pixels per CSS pixel

On desktop, browser zoom changes both the DPR and the CSS sizes, so the product stays close to the monitor’s real resolution. On Windows at 150% scaling, a 3840 px wide 4K monitor reports screen.width = 2560 and DPR = 1.5.

The viewport meta tag and DPR

DPR only gives a readable phone layout if the page opts in. Without this tag, mobile browsers lay the page out on a wide virtual viewport and shrink it to fit, making text tiny. Apple’s Safari Web Content Guide gives 980 CSS px as Safari’s default width. Rulers, pixel tools and anything sized in CSS units need the tag to behave predictably:

<meta name="viewport" content="width=device-width, initial-scale=1">

With width=device-width, the layout viewport matches the device’s CSS width (393 px on an iPhone 15), and the browser draws each CSS pixel with DPR × DPR device pixels. The tag doesn’t change devicePixelRatio itself; it changes how many CSS pixels the layout is given.

Using DPR in CSS: resolution queries and image-set()

Media queries accept three equivalent units for density:

Unit Meaning DPR 2 equals
dppx (or x) Dots per CSS pixel 2dppx, 2x
dpi Dots per CSS inch (96 CSS px) 192dpi
dpcm Dots per CSS centimeter ≈ 75.6dpcm

Note that 192dpi here means 2 × 96, a CSS unit, not the screen’s physical PPI. For background images, image-set() picks the right file by density:

.hero {
  background-image: image-set(
    url("hero-1x.jpg") 1x,
    url("hero-2x.jpg") 2x
  );
}

How to measure on screen with DPR

Measure your CSS pixels per inch with a card

You don’t need to know your PPI or DPR. Calibration measures the result directly:

  1. Set browser zoom to 100% (Ctrl/Cmd + 0 on desktop). On a phone, don’t pinch-zoom.
  2. Open the calibration page and hold a standard bank card (85.60 mm, ISO/IEC 7810 ID-1) against the screen.
  3. Drag the outline until it matches the card edge exactly. The ruler now knows how many CSS pixels span 85.60 mm.
  4. Read the scale. CSS px per inch = pixels across the card ÷ 3.370 (85.60 ÷ 25.4).
  5. Check it by measuring a second known object, such as a banknote or an A4 sheet.

Worked example (iPhone 15): 460 PPI ÷ DPR 3 ≈ 153.3 CSS px per inch, so the card should span about 153.3 × 3.370 ≈ 517 CSS px. A naive 96 px-per-inch ruler would draw the card at only about 324 px, which is 37% too small.

Measure a UI element in CSS pixels from a screenshot

  1. Take a screenshot of the screen you want to inspect.
  2. Find your DPR with window.devicePixelRatio, or from the tables above.
  3. Measure the element in the screenshot in image pixels, using an image editor or a pixel ruler.
  4. Divide by DPR. A 132 px button in an iPhone 15 screenshot is 132 ÷ 3 = 44 CSS px, which is Apple’s recommended minimum tap target in points.
  5. Convert to real size if needed: CSS px ÷ (PPI ÷ DPR) gives inches. 44 ÷ 153 ≈ 0.29 in ≈ 7.3 mm. Check it physically with the calibrated ruler on phone.

Common device pixel ratio mistakes

  • Assuming DPR is a whole number. Android and Windows produce values like 1.25, 2.625 and 2.75. Round canvas sizes with Math.round to avoid blur.
  • Caching DPR once at page load. It changes when the window moves to another monitor or the user zooms. Re-read it on change.
  • Treating dpi in CSS as physical PPI. A CSS dpi is per CSS inch, which is rarely a real inch.
  • Sending 3× images to every device. They triple width and height, so about nine times the pixels of 1×. Use srcset with width descriptors and sizes so the browser picks.
  • Measuring screenshots as if they were CSS pixels. Always divide by DPR first.
  • Sizing a canvas once. If the user zooms or moves the window to another monitor, the canvas goes blurry. Re-run the sizing code on change (see the matchMedia example above).
  • Using CSS cm or in for real-world sizes. They’re defined from the 96 px reference, not your screen. Calibrate instead.

Troubleshooting

Problem Likely cause Fix
Canvas drawing looks blurry Backing store sized in CSS pixels Multiply canvas.width/height by DPR and ctx.scale(dpr, dpr)
DPR reads 1.1 or 0.9 on desktop Browser zoom isn’t 100% Press Ctrl/Cmd + 0
Thin lines vary between 1 and 2 device pixels Fractional DPR and subpixel positions Snap coordinates to device pixels: Math.round(x * dpr) / dpr
Online ruler too short or too long CSS inch ≠ real inch on this device Calibrate with a card on the calibration page
Images sharp on desktop, soft on phone Only a 1× source supplied Add 2× (and optionally 3×) sources in srcset or image-set()
DPR differs between Chrome and Firefox on the same PC Each browser keeps its own zoom level Check both are at 100%

Sources

  • W3C, CSS Values and Units Module Level 3 (reference pixel, 1in = 96px).
  • W3C, Media Queries Level 4 (resolution and dppx).
  • Apple: iPhone technical specifications (resolution and PPI by model).
  • ISO/IEC 7810: ID-1 card size, 85.60 × 53.98 mm.
  • MDN Web Docs: Window.devicePixelRatio, responsive images (srcset).
  • Apple, Google and Samsung published display specifications.
  • Apple Safari Web Content Guide: configuring the viewport (980 px default).
  • Apple Human Interface Guidelines (scale factors, 44 pt minimum tap target).
  • Android Developers: “Support different pixel densities” (dp and density buckets).