CSS Pixels to Device Pixels Converter
Use the CSS Pixels to Device Pixels Converter to see how many physical device pixels a CSS dimension actually renders to at a given device pixel ratio (DPR). Enter a CSS Width and CSS Height, click Detect My DPR to pull your own screen's ratio (or type one in manually), and you'll get the physical Device Pixel Size plus a ready-made table of 1x / 2x / 3x export sizes for handing off to a designer. Use the monitor viewing distance calculator online any time you need a fast, accurate figure without doing the arithmetic yourself.
Ever wonder why a button that looks perfectly sized on your laptop appears tiny or blurry on a high-density phone screen? The CSS Pixels to Device Pixels Converter gives you the exact physical pixel count your display device will render — knowledge that drives pixel-perfect layouts, correctly sized image assets, and confident responsive design across every screen you target. Whether you're doing mobile development with dp units or debugging a high DPI drawing surface element, understanding how hardware pixels into css pixels relate is foundational to professional web design and mobile UI design.
Using a CSS Pixels to Device Pixels Converter — Core Formulas Explained
At the heart of this css pixels to device pixels converter sit two reciprocal formulas. Every rendering engine, every mobile layout engine, and every stylesheet condition ultimately reduces to these two relationships: The calculate a retina distance breaks the math down step by step so the answer is never a black box.
Forward conversion — CSS pixels to device pixels:
$$\text{Device Pixels} = \text{CSS Pixels} \times \text{Device Pixel Ratio}$$Reverse conversion — device pixels back to CSS pixels:
$$\text{CSS Pixels} = \frac{\text{Device Pixels}}{\text{Device Pixel Ratio}}$$A pixel ratio of 1 means the panel is a baseline mdpi panel where 1dp equal 1px by definition. A ratio of 2 is the classic high-density mapping, and ratios of 3 or 4 are found on xxhdpi and xxxhdpi handsets. The conversion process is transparent at runtime — the rendering engine handles it silently — but as a designer developer building responsive pixel design, you need to perform it consciously when sizing image assets, setting drawing surface resolution, or translating Material Design dp specs into stylesheet values.
To read the current pixel ratio in JavaScript, query the window.devicePixelRatio property exposed on the Window interface:
// Log the device pixel ratio of the current display device
console.log('DPR:', window.devicePixelRatio);
The devicePixelRatio property returns a double representing the ratio of hardware dots to logical units for the current output panel. On a standard desktop panel it returns 1; on a high-density MacBook or iPhone it typically returns 2; on high-end handsets it can reach 3 or even 4. User zoom also alters this value — when a user magnifies pages using the zoom feature, the ratio changes proportionally, which is why tracking display resolution or zoom level changes dynamically matters for drawing-heavy applications.
Understanding Physical Pixels and CSS Pixels — The Reference Pixel Concept
What Makes a Physical Pixel Different From a CSS Pixel
The distinction between a hardware pixel and a software pixel is one of the most misunderstood concepts in front-end development. A hardware pixel is a single light-emitting element on your physical panel — the smallest addressable dot the display technology can illuminate. A CSS pixel (also called a software pixel) is an abstraction layer defined by the web standards body to give page designers a stable, device-independent measurement unit that produces consistent physical dimensions across different rendering targets. The diagonal to dimensions converter handles the conversion entirely client-side, so nothing you enter is ever transmitted.
"The px unit thus shields you from having to know the resolution of the device. Whether the output is 96 dpi, 100 dpi, 220 dpi or 1800 dpi, a length expressed as a whole number of px always looks good and very similar across all devices." — W3C CSS Values and Units Module
The web standards body anchors the reference pixel to a visual angle rather than a strict physical size. Specifically, the absolute length units in stylesheets — which include the physical units inches, millimeters, points and the angular size unit px — are defined relative to an assumed reading distance. For reading at arm's length, 1px corresponds to about 0.26 mm (1/96 inch). The specification defines a nominal viewing distance of 28 inches, which produces a geometric angle of approximately 0.0213 degrees per pixel on a 96dpi reference device.
The CSS 2.1 specification and its successor, the CSS Values Level 3 module (a candidate recommendation), both state:
"Pixel units are relative to the resolution of the viewing device, i.e., most often a computer display. If the pixel density of the output device is very different from that of a typical computer display, the user agent should rescale pixel values."
In practice, the rendering client — whether Gecko, a Chromium-based engine, or WebKit — applies this adjustment automatically. On a standard desktop panel, the mapping is 1:1. On a 600dpi laser printer, the client must adjust those dot counts upward so that a ten-dot font on that printer still looks like the designer intended, not a hairline sliver. On super-high-res panels and modern output devices with a dot density exceeding 200 ppi, the OS scales up so that two hardware dots (or more) render each logical unit.
To get an intuitive feel for the original px unit: imagine a CRT panel from the 1990s — the smallest dot it could show measured roughly 1/100th of an inch (0.25 mm). The px unit inherited its name from those dots on low-density panels of 72-96dpi. Modern high-resolution panels and high DPI technology have made this abstraction layer essential for cross-platform consistency in web design.
The relationship can be expressed precisely as:
$$\text{software pixel} = \frac{\text{hardware pixel}}{\text{device pixel ratio}}$$For example, on a panel with 1920 hardware dots across and a pixel ratio of 2, the 960 logical units wide region is what your stylesheet rules and resolution conditions see. That 960px threshold is the value you use in your stylesheet file, not the 1920px hardware count. This is the core insight behind converting css pixel into hardware pixel counts for responsive design.
Correcting Pixel Density in a Canvas Element
The <canvas> element is one place where the abstraction breaks down visibly. When you set canvas.width = 400, you are specifying 400 logical units — but on a high-density panel with a ratio of 2, the rendering engine stretches those 400 units across 800 hardware dots, producing blurry graphics. Correcting resolution in a drawing surface requires you to scale the drawing area up by the devicePixelRatio and then shrink it back down with inline styles, in order to properly scale pixels to their intended size:
function setupHiDPICanvas(canvas, width, height) {
const dpr = window.devicePixelRatio || 1;
// Set the drawing surface resolution to match hardware dots
canvas.width = width * dpr;
canvas.height = height * dpr;
// Shrink the rendered size back to logical unit dimensions
canvas.style.width = width + 'px';
canvas.style.height = height + 'px';
// Scale the drawing context so positions remain in logical units
const ctx = canvas.getContext('2d');
ctx.scale(dpr, dpr);
return ctx;
}
Without this correction, a drawing surface resolution mismatch on a HiDPI or high-density panel produces visibly soft edges on typography, graphics, and UI icons. With the correction applied, every position in your drawing code remains in logical units while the surface renders crisply at the full dot resolution of the panel.
Convert CSS Pixel into Hardware Pixel — Android dp Reference and Worked Examples
CSS px to Android dp and the dp to px Formula
In mobile development for Android, the measurement unit for device independent sizing is the dp (density-independent pixel), sometimes written dip. dp only needs to be used when building for Android; on the web platform, logical stylesheet units already serve the same device-independent role. However, when you are implementing a design specification — which is always written in dp — you need to translate those dp values into stylesheet px values for your rules. These are css length units that work across measurement units in both ecosystems.
Three foundational equivalences govern this dp conversion:
96 css-px ≈ 1 inch
160 dp ≈ 1 inch (Android baseline: 160 dp per inch)
96 css-px ≈ 160 dp
From these, the dp to pixels formula for stylesheets follows directly:
$$\text{css-px-length} = \text{round}\!\left(\text{dp-length} \times \frac{96}{160}\right)$$The Android density bucket system assigns a dp multiplier to each density tier, with an mdpi panel (160dpi) as the baseline where 1dp equal 1px:
| Density Bucket | Screen Density (dpi / ppi) | dp Multiplier | 1 dp equals |
|---|---|---|---|
| ldpi | ~120 dpi | 0.75× | 0.75 px ldpi |
| mdpi | ~160 dpi | 1.0× | 1 px mdpi |
| hdpi | ~240 dpi | 1.5× | 1.5 px hdpi |
| xhdpi | ~320 dpi | 2.0× | 2 px xhdpi |
| xxhdpi | ~480 dpi | 3.0× | 3 px xxhdpi |
| xxxhdpi | ~640 dpi | 4.0× | 4 px xxxhdpi |
The Google design system is built around maintaining uniform physical measurements across platforms. This is why the Android API guide dedicates a section to converting dp units to pixel units: physical measurement in your UI directly affects usability. Consider a fling gesture threshold:
"Imagine an application in which a scroll or fling gesture is recognized after the user's finger has moved by at least 16 pixels. On a baseline screen, the user must move by 16 pixels / 160 dpi, which equals 1/10th of an inch (2.5 mm). On a high-density display (240 dpi), the user must move by 16 pixels / 240 dpi — only 1/15th of an inch (1.7 mm). The distance is much shorter and the application appears more sensitive." — Android API Guide
This explains why the ideal touch size and snackbar height specifications in the Google component guide are expressed in dp: the physical size of an interactive element must stay the same regardless of dot density to maintain ergonomic usability.
Worked Example 1 — Android Button Sizing at xxhdpi
Suppose the design spec defines a component with min-height: 36dp and min-width: 216dp (scaled to xxhdpi, DPR = 3). Using the xxhdpi multiplier of 3×:
- Identify the dp values: min-height = 36 dp, min-width = 216 dp, multiplier = 3 (xxhdpi)
- Apply the multiplication: $$\text{px} = \text{dp} \times \text{multiplier}$$
- Calculate min-height: $$36 \times 3 = 108\text{ px}$$
- Calculate min-width: $$216 \times 3 = 648\text{ px}$$
For a snackbar component at xxhdpi with min-height: 48dp and min-width: 288dp:
/* xxhdpi — dp multiplier 3× */
.snackbar {
min-height: 144px; /* 48dp × 3 */
min-width: 864px; /* 288dp × 3 */
border-radius: 6px; /* 2dp × 3 */
}
At mdpi (1×), the same component becomes:
/* mdpi — dp multiplier 1× */
.snackbar {
min-height: 48px;
min-width: 288px;
border-radius: 2px;
}
Worked Example 2 — Small UI Element at Various DPRs
Consider a simple stylesheet rule for a small status indicator:
.bar {
width: 2px;
height: 2px;
}
Those 2 logical units define the element's size in the coordinate space your rendering engine uses. The actual hardware dot count rendered depends entirely on the ratio:
- DPR 1 (mdpi, baseline panel): 2 × 1 = 2 hardware dots wide × 2 tall = 4 total
- DPR 2 (high-density, xhdpi): 2 × 2 = 4 hardware dots wide × 4 tall = 16 total
- DPR 3 (xxhdpi): 2 × 3 = 6 hardware dots wide × 6 tall = 36 total
- DPR 4 (xxxhdpi): 2 × 4 = 8 hardware dots wide × 8 tall = 64 total
This is why image sizing and asset preparation require distinct 1×, 2×, and 3× variants. On a high-density panel, a 1× image asset is spread across four hardware dots per logical unit, producing a blurry result unless you supply a high-resolution version via a high DPI resolution condition or the srcset attribute. The image quality difference is immediately visible to users.
Worked Example 3 — Border-Radius Rounding Edge Case
The 96 css-px ≈ 160 dp formula introduces rounding situations that can break sub-pixel rendering. Consider a border-radius: 2dp value:
A value of 1.2px cannot be expressed as a whole logical unit, so it rounds to 1px. This can produce rounding errors in structures that rely on precise geometric proportioning. The practical takeaway: always verify your dp-to-px conversions with the formula before applying them, especially for small interface elements where a single dot difference is noticeable. At xxhdpi (DPR 3), 2dp × 3 = 6px — the multiplier eliminates the rounding problem entirely because the density bucket factor produces clean integers.
/* Correct border-radius for xxhdpi (DPR 3): */
.card { border-radius: 6px; } /* 2dp × 3 — no rounding error */
/* mdpi formula result — rounds incorrectly: */
/* 2dp × (96/160) = 1.2px → rounds to 1px */
.card-mdpi { border-radius: 1px; } /* acceptable fallback */
Resolution conditions let you deliver targeted asset variants and structural thresholds based on dot density. Using the mdpi panel (160dpi) as baseline where 1dp equals 1px and px wherever dp is written in the spec:
/* Baseline — mdpi (160dpi), DPR 1 */
.icon { background-image: url('icon-1x.png'); }
/* hdpi panel — DPR 1.5 */
@media (min-resolution: 144dpi) {
.icon { background-image: url('icon-1.5x.png'); }
}
/* xhdpi panel — DPR 2 */
@media (min-resolution: 192dpi) {
.icon { background-image: url('icon-2x.png'); }
}
/* xxhdpi panel — DPR 3 */
@media (min-resolution: 288dpi) {
.icon { background-image: url('icon-3x.png'); }
}
/* xxxhdpi panel — DPR 4 */
@media (min-resolution: 384dpi) {
.icon { background-image: url('icon-4x.png'); }
}
These resolution thresholds define your breakpoints for asset delivery. A well-structured set of resolution conditions covering these thresholds and providing suitable assets ensures that your design maintains quality across the full range of dot-density tiers in the Android ecosystem and on high-resolution desktop panels.
Simple Converter Reference — Compatibility and Screen Resolution Monitoring
window.devicePixelRatio Browser Support and the CSS Resolution Media Query
The window.devicePixelRatio property is the primary web API for reading the pixel ratio of the current panel at runtime. It is part of the Window interface and is well-supported across all modern clients. The resolution condition in stylesheets provides an alternative that avoids JavaScript for static asset decisions.
| Feature | Chrome | Firefox (Gecko) | Safari | Edge | Opera |
|---|---|---|---|---|---|
window.devicePixelRatio | Yes (all versions) | Yes (18+) | Yes (all versions) | Yes (all versions) | Yes |
CSS resolution media query | Yes | Yes (8+ with -moz-) | Yes (16+) | Yes | Yes |
matchMedia (MediaQueryList) | Yes (9+) | Yes (6+) | Yes (5.1+) | Yes (12+) | Yes |
All major clients — including mobile environments like the Android web client and phone web client — support window.devicePixelRatio and the resolution stylesheet condition. The MDN Web Docs confirm broad support across both desktop and mobile platforms. Note that Gecko (Firefox's rendering engine) does expose additional ratio metadata to chrome scripts, but normal web pages should rely only on the standard devicePixelRatio property on the Window interface.
Monitoring Screen Resolution and Zoom Level Changes Dynamically
The devicePixelRatio value is not static — it shifts when the user activates zoom, the page zoom level changes, or the window is moved to a panel with a different dot density. To respond to these changes in real time, you use the MediaQueryList API with matchMedia. This approach also works for the zoom feature on tablets and desktop clients.
function monitorPixelRatio() {
const dpr = window.devicePixelRatio;
const query = `(resolution: ${dpr}dppx)`;
const mediaQueryList = window.matchMedia(query);
// Handler fires when the resolution or zoom level changes
function handleChange(event) {
console.log('DPR changed. New ratio:', window.devicePixelRatio);
// Re-run your drawing surface correction or asset-swapping logic here
monitorPixelRatio(); // re-register for the next change
}
// Register the listener — it fires once when the condition no longer matches
mediaQueryList.addEventListener('change', handleChange, { once: true });
}
monitorPixelRatio();
This pattern correctly handles zoom level changes because each time the user zooms in or out — effectively choosing to magnify pages — the current resolution condition stops matching and the handler fires. You then re-register the listener against the new ratio value. The approach works in all modern clients and is the technique documented in the MDN web APIs reference for monitoring display resolution changes.
For a simpler, static HTML site use case — such as selecting the right background image at a responsive threshold — a pure stylesheet condition without JavaScript is cleaner and faster for the rendering pipeline:
/* High-density panel — retina media query */
@media (-webkit-min-device-pixel-ratio: 2),
(min-resolution: 192dpi),
(min-resolution: 2dppx) {
.hero {
background-image: url('[email protected]');
}
}
The dppx unit (dots per pixel) is the resolution condition's native way to express the ratio, and it maps exactly to the window.devicePixelRatio value. Using both the -webkit- prefixed version and the standard resolution condition ensures compatibility with older WebKit-based clients while targeting all current panel environments.
Real-World Usage Notes for CSS px Conversion
A few practical considerations that affect how you apply px conversion in production web design and mobile development workflows:
- Viewport and page structure: Your stylesheet rules operate entirely in logical units. The viewport meta tag on mobile devices maps the layout region width to logical units, not hardware dots. A
width=device-widthdeclaration on an iPhone with a 2× ratio sets the region to 375 logical units, not the 750 hardware dots the panel actually has. This cross-platform consistency is responsible for eliminating the need to adjust dot counts manually in most responsive design scenarios. - Sub-pixel positioning: Rendering engines use sub-pixel positioning internally to improve quality on high-density panels. When element positions in logical units don't map to clean hardware dot boundaries, the renderer applies anti-aliasing. This is usually desirable, but it can cause single-dot borders to look thinner or lighter than expected on high-density panels.
- The sp unit in Android: Android also defines an sp unit (scale-independent pixel) for typography — it behaves like dp but also respects the user's preferred font scale setting. For the purposes of this css pixels to device pixels converter, treat sp the same as dp for conversion calculations.
- Element position and coordinates: APIs like
elementFromPointandgetBoundingClientRectreturn values in logical units, not hardware dots. When working with drawing surface positions or pointer event positions, always work in logical unit space and only convert to hardware dots at the drawing surface layer. - Scalability and accessibility: User zoom is an accessibility feature. Because the zoom feature changes
window.devicePixelRatio, building zoom-aware applications that re-run their conversion calculations on ratio change improves usability for users who need larger text and interface elements. - Image quality on high-density panels: High-resolution devices expect high-resolution images. Supplying only a 1× image on a high dot-density panel results in the rendering engine upscaling the image across 4 hardware dots per logical unit (at DPR 2), causing visible blurriness. Ensure correct asset preparation by providing 2× and 3× variants and delivering them via resolution-based conditions or the
srcsetattribute. - Desktop resolution context: The 96dpi assumption embedded in stylesheet specifications is a simplification. Many laptop and tablet panels run at 127–130 ppi, meaning 1 logical unit ≠ exactly 1 hardware dot even at OS scale factor 1. For dot-level precision in graphic design work, verify the actual dpi value of your target panel and apply the conversion formula accordingly. Tools like Google Resizer let you preview how your structure renders across common responsive thresholds at different density tiers.
CSS Specification Reference for Pixel Units and Physical Measurement
Understanding which specification governs the behavior of logical stylesheet units and pixel sizing helps you write future-proof code. The table below summarizes the key specification references for px unit definition, absolute length units, and the devicePixelRatio property:
| Specification | Status | Key Definitions |
|---|---|---|
| CSS Values and Units Module Level 3 (W3C Candidate Recommendation) | Candidate Recommendation | Defines px as angular size unit; anchors 96 css px ≈ 1 inch; defines the standard dot reference at 96dpi / arm's length |
| CSS Values and Units Module Level 4 | Working Draft | Extends Level 3; adds dppx unit for resolution conditions; refines absolute length unit definitions |
| CSS 2 / CSS 2.1 Specification | W3C Recommendation | Original definition of the logical pixel unit; established that the rendering client should adjust dot counts for high/low density output targets; noted 72-96dpi typical range |
| CSSOM View Module (Window.devicePixelRatio) | Living Standard | Defines the devicePixelRatio property on the Window interface; specifies behavior under user zoom and page zoom |
| CSS Media Queries Level 4 (resolution feature) | Candidate Recommendation | Defines resolution media feature; supports dpi, dpcm, and dppx units for density-based conditions |
The progression from the original specification through the current Level 4 documents reflects the evolution of panel technology. Early specifications treated px as a physical unit tied to hardware dots; modern specifications formally recognize the abstraction layer, defining px relative to a viewing angle at arm-length reading distance. This shift — documented in the normative note of the CSS 2.1 specification — was made explicitly because too much existing content relied on the 96dpi assumption, and changing it would have broken that content. The current definition gives front-end developers and page designers the well-defined relations they need between logical unit dimensions and physical measurements on any rendering target, from a 600dpi printer to a 127ppi laptop to an xxxhdpi phone panel.
For mobile developers and web designers implementing design specifications, this history explains why using px wherever dp is called for in a web context is technically correct: the stylesheet px is already a device-independent unit, just anchored to a 96dpi baseline rather than Android's 160dpi baseline. The simple conversion formula — css-px = round(dp × 96/160) — bridges these two baselines and lets you convert css pixel into hardware pixel counts with confidence. The 1 to 1 conversion used in the Polymer library and many implementations works because most devices cluster around DPR 1 for their logical unit scale factor, making 1 logical unit equal to 1 dp a reasonable practical approximation that maintains cross-device consistency for the majority of modern devices without the complexity of per-device density calculations.
Frequently Asked Questions
- What is a CSS pixel and how does it differ from a device pixel?
- A CSS pixel (also called a logical pixel) is an abstract unit used in web design that represents a consistent visual size regardless of screen density. A device pixel (or hardware pixel) is an actual physical dot on a screen. On standard 1× displays they are the same, but on Retina or HiDPI displays, one CSS pixel maps to 2 or more device pixels, producing sharper visuals.
- What is the Device Pixel Ratio (DPR)?
- The Device Pixel Ratio (DPR) is the ratio of physical (device) pixels to CSS (logical) pixels on a screen. A DPR of 2 means that for every 1 CSS pixel, there are 2 physical pixels in each dimension — or 4 pixels in total area. You can check a device's DPR in JavaScript using window.devicePixelRatio.
- How do I convert CSS pixels to device pixels?
- Multiply your CSS pixel value by the Device Pixel Ratio. For example, a 200px CSS element on a display with a DPR of 2 occupies 400 device pixels linearly (and 200×200 = 40,000 CSS pixel area vs 400×400 = 160,000 device pixel area).
- What DPR does an iPhone or MacBook Retina display use?
- Most iPhones (non-Pro) and MacBook Retina displays use a DPR of 2×. iPhone Pro models (e.g. iPhone 14 Pro and later) typically use a DPR of 3×. You can confirm the exact value for any device using window.devicePixelRatio in a browser console.
- Why does DPR matter for web and app development?
- DPR matters because images and graphics defined in CSS pixels may appear blurry on high-density screens if not provided at the correct resolution. For a 2× display, images should be served at double the CSS dimensions to appear crisp. This is commonly handled with srcset attributes, CSS media queries targeting device-pixel-ratio, or the HTML canvas scaling technique.
- Does a higher DPR always mean better image quality?
- A higher DPR gives you more physical pixels to render each CSS pixel, which can produce sharper text and images. However, it also means your graphics files need to be larger to take full advantage of the display. If you serve a standard-resolution image on a 3× screen, it will appear blurry compared to one served at the native resolution.
- How is CSS px different from Android dp (density-independent pixels)?
- Android dp is similar in concept to CSS px — both are device-independent units designed to look consistent across screens of different densities. On a 160 DPI baseline screen, 1dp ≈ 1 physical pixel, similar to how 96 CSS px ≈ 1 inch at standard density. While the concepts align closely, they come from different ecosystems and should not be considered fully interchangeable without accounting for platform-specific density values.
- Can the Device Pixel Ratio be a non-integer value?
- Yes. Some devices — particularly certain Android phones and Windows laptops — have fractional DPR values like 1.5× or 2.5×. This can sometimes cause sub-pixel rendering issues where pixels don't align perfectly to physical pixels, potentially causing slight blurriness on borders or fine lines.