Device Pixel Ratio (DPR) is accessed through window.devicePixelRatio, which reports the ratio between physical pixels and CSS pixels on your display:
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.
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
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
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.
| 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 |
| 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 |
Windows allows arbitrary display scaling percentages (100%, 125%, 150%, 175%, 200%, etc.), resulting in fractional DPR values:
1.25 (125% scaling)1.5 (150% scaling)1.75 (175% scaling)2.25 (225% scaling)macOS typically uses whole numbers (1×, 2×) because it offers "Looks like" resolution presets.
Serving appropriately-sized images for different pixel densities:
// JavaScript detection
if (window.devicePixelRatio >= 2) {
img.src = 'image@2x.jpg'; // Load high-res version
}
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!
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 */
}
}
| 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 |
When users zoom in/out using Ctrl+Plus or Ctrl+Minus, devicePixelRatio changes:
Impact: DPR is not purely hardware-based; user zoom affects the value!
All modern browsers (Chrome, Firefox, Safari, Edge) report devicePixelRatio consistently on the same hardware with the same OS settings and zoom level.
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
Device Pixel Ratio is a highly effective fingerprinting attribute, especially when combined with screen resolution. It reveals specific hardware details and display configurations.
While there are only ~10 common DPR values, the distribution is fragmented:
This provides roughly 3-4 bits of entropy (dividing users into 8-16 groups).
DPR strongly indicates device category:
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.
Advertisers can identify "premium device" users (iPhone, MacBook) via DPR and serve different ads or prices.
DPR remains constant across browsing sessions (unless you change display settings), making it a stable long-term identifier.
Because browser zoom affects DPR, trackers can potentially:
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
Strict Fingerprinting Protection: May report rounded or standardized DPR values
Effect: Reduces precision but doesn't eliminate fingerprinting entirely
You can change display scaling in OS settings to alter DPR, but:
Some anti-fingerprinting extensions spoof devicePixelRatio, but:
Rather than focusing on DPR alone, use comprehensive privacy tools:
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.