Device Pixel Ratio

Back to Main

Your Device Pixel Ratio

Loading...

1. Technical Classification

Display Hardware JavaScript API Window Object High-DPI Detection

Device Pixel Ratio (DPR) is accessed through window.devicePixelRatio, which reports the ratio between physical pixels and CSS pixels on your display:

2. Background & Purpose

Device Pixel Ratio was introduced to address the challenge of high-DPI displays (Retina, 4K, etc.) where physical pixels are much smaller than traditional pixels. The concept emerged with smartphones and Apple's Retina displays in 2010.

The Problem: CSS Pixels vs Physical Pixels

Traditional Display (DPR = 1)

Physical pixels: 1920×1080

CSS pixels: 1920×1080

Relationship: 1 CSS pixel = 1 physical pixel

Result: Simple 1:1 mapping; what you specify in CSS matches screen pixels

Retina Display (DPR = 2)

Physical pixels: 2880×1800

CSS pixels: 1440×900

Relationship: 1 CSS pixel = 4 physical pixels (2×2 grid)

Result: Images and text can be rendered much sharper if designed for it

Why CSS Pixels Exist

Without CSS pixels, websites would appear tiny on high-DPI displays. A button designed as "100 pixels wide" would be half the physical size on a 2× display. CSS pixels maintain consistent sizing across devices while allowing higher resolution rendering.

Historical Context

3. Common Device Pixel Ratios

Desktop/Laptop Displays

DPR Value Description Example Devices
1.0 Standard DPI Traditional 1080p monitors, budget laptops, older displays
1.25 Windows 125% scaling 1080p displays with Windows scaling for readability
1.5 Windows 150% scaling Common on 1440p or 4K displays with comfortable scaling
2.0 Retina / HiDPI MacBook Pro/Air (Retina), Windows 200% scaling, many 4K displays
2.25 Windows 225% scaling High-resolution Windows laptops with aggressive scaling
3.0 Very high DPI Microsoft Surface (some models), 5K iMac at native resolution

Mobile Devices

DPR Value Device Category Examples
2.0 Standard Retina iPhone 11, iPhone SE, older Android flagships
3.0 High-end phones iPhone 15/14/13/12 Pro, Samsung Galaxy S series, Google Pixel
4.0 Ultra-high DPI phones Some Android flagships (Sony Xperia, Samsung S21 Ultra)
2.0 Tablets iPad Air, iPad Pro, high-end Android tablets

Fractional DPR Values

Windows allows arbitrary display scaling percentages (100%, 125%, 150%, 175%, 200%, etc.), resulting in fractional DPR values:

macOS typically uses whole numbers (1×, 2×) because it offers "Looks like" resolution presets.

4. Legitimate Uses

Responsive Images

Serving appropriately-sized images for different pixel densities:

Responsive image // JavaScript detection if (window.devicePixelRatio >= 2) { img.src = 'image@2x.jpg'; // Load high-res version }

Canvas & Graphics Rendering

Rendering sharp graphics on high-DPI displays:

// Scale canvas for sharp rendering on Retina displays const canvas = document.querySelector('canvas'); const ctx = canvas.getContext('2d'); const dpr = window.devicePixelRatio || 1; // Set canvas pixel dimensions canvas.width = 800 * dpr; canvas.height = 600 * dpr; // Scale CSS dimensions canvas.style.width = '800px'; canvas.style.height = '600px'; // Scale drawing operations ctx.scale(dpr, dpr); // Now draw at CSS coordinates (800×600) ctx.fillRect(0, 0, 100, 100); // Crisp on Retina!

Media Queries

CSS can target different pixel densities:

/* Standard resolution */ .logo { background-image: url('logo.png'); } /* High-DPI displays (Retina) */ @media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) { .logo { background-image: url('logo@2x.png'); background-size: 100px 50px; /* Scale to CSS dimensions */ } }

Performance Optimization

UI Scaling

5. Platform & Browser Behavior

Operating System Differences

Platform DPR Behavior Notes
macOS Typically whole numbers (1, 2) "Looks like" presets; 2× is standard for Retina displays
Windows Fractional values common 125%, 150%, 200% scaling options produce 1.25, 1.5, 2.0 DPR
Linux Varies by DE GNOME, KDE offer scaling; typically 1 or 2
iOS 2 or 3 iPhone (older): 2, iPhone Pro models: 3
Android 1.5 to 4 Wide range depending on device tier

Browser Zoom Affects DPR

Important: Zoom Changes DPR!

When users zoom in/out using Ctrl+Plus or Ctrl+Minus, devicePixelRatio changes:

  • Base DPR: 2.0 on MacBook Pro
  • After 110% zoom: DPR becomes ~2.2
  • After 90% zoom: DPR becomes ~1.8

Impact: DPR is not purely hardware-based; user zoom affects the value!

Cross-Browser Consistency

All modern browsers (Chrome, Firefox, Safari, Edge) report devicePixelRatio consistently on the same hardware with the same OS settings and zoom level.

Multi-Monitor Setups

Mixed DPR Environments

Scenario: Laptop (DPR = 2) connected to external monitor (DPR = 1)

Behavior: devicePixelRatio reports the ratio of the monitor currently displaying the browser window

Dynamic Change: Moving window between monitors can change the reported DPR

6. Privacy Implications & Tracking Risks

Privacy Risk: HIGH

Device Pixel Ratio is a highly effective fingerprinting attribute, especially when combined with screen resolution. It reveals specific hardware details and display configurations.

Why DPR is Powerful for Fingerprinting

1. High Entropy (Distinctiveness)

While there are only ~10 common DPR values, the distribution is fragmented:

  • DPR = 1: Older desktops, budget devices (~20-30% of users)
  • DPR = 2: MacBooks, modern laptops, iPhones (~40-50% of users)
  • DPR = 1.25, 1.5, 2.25: Windows scaling variations (~15-20%)
  • DPR = 3, 4: High-end mobile devices (~10-15%)

This provides roughly 3-4 bits of entropy (dividing users into 8-16 groups).

2. Device Type Inference

DPR strongly indicates device category:

  • DPR = 1: Likely older desktop/laptop with standard display
  • DPR = 2 + 2560×1600 CSS pixels: MacBook Pro 13"
  • DPR = 3 + 390×844 CSS pixels: iPhone 15/14/13
  • DPR = 1.25: Windows user with 125% scaling

3. Combined with Screen Resolution

Example Fingerprint:

CSS Resolution: 1440×900 | DPR: 2.0

Physical Resolution: 2880×1800 (calculated: 1440×2 by 900×2)

Identification: This is specifically a MacBook Pro 15" (pre-2021) or 14"/16" M1 Pro/Max in scaled mode

The combination of screen resolution + DPR dramatically increases uniqueness.

Real-World Tracking Scenarios

Device-Specific Targeting

Advertisers can identify "premium device" users (iPhone, MacBook) via DPR and serve different ads or prices.

Cross-Session Persistence

DPR remains constant across browsing sessions (unless you change display settings), making it a stable long-term identifier.

Zoom-Based Detection

Because browser zoom affects DPR, trackers can potentially:

7. Protection & Mitigation

1. Privacy Browsers

Tor Browser

Protection: Reports fixed DPR = 1.0 for all users

Method: Forces all displays to appear as standard DPI

Trade-off: Images and canvas may appear less sharp on high-DPI displays

Brave Browser

Strict Fingerprinting Protection: May report rounded or standardized DPR values

Effect: Reduces precision but doesn't eliminate fingerprinting entirely

2. Adjust Display Scaling (Not Recommended)

You can change display scaling in OS settings to alter DPR, but:

3. Browser Extensions

Some anti-fingerprinting extensions spoof devicePixelRatio, but:

4. Multi-Layered Privacy Strategy

Rather than focusing on DPR alone, use comprehensive privacy tools:

  1. Block Third-Party Cookies: Prevents cross-site tracking
  2. Use Tracker Blockers: uBlock Origin, Privacy Badger
  3. Privacy-Respecting Browser: Firefox, Brave with enhanced protections
  4. VPN or Tor: For sensitive activities requiring anonymity
Practical Advice

Device Pixel Ratio is a strong fingerprinting attribute, but attempting to hide it can break website functionality. For most users, focus on blocking third-party trackers and cookies. For high-privacy needs, use Tor Browser which comprehensively protects against all fingerprinting including DPR.

8. Learn More