MM to PX for JavaScript
Convert millimeters to pixels and generate a reusable JavaScript conversion expression.
JavaScript dimensions
JavaScript output
JavaScript output
Use 96 PPI for CSS pixels or supply the actual device or export resolution your code targets.
How MM to PX for JavaScript Works
Enter the mm value
Type the millimeter value you want to convert programmatically.
Set the target PPI
Choose 96 PPI for DOM/CSS work, or enter a custom resolution for canvas or export code.
Copy the code snippet
The calculator generates a JavaScript expression you can paste directly into your codebase.
When working with the DOM or CSS in JavaScript, pixel values correspond to CSS reference pixels at 96 PPI. For HTML Canvas or image-processing libraries, you may need a different resolution. The generated conversion function lets you pass any millimeter value and receive the pixel equivalent at your chosen PPI.
MM to PX for JavaScript Formula
const px = mm => mm * DPI / 25.4 Conversion Formula This one-liner converts any millimeter value to pixels at the specified DPI. At 96 PPI (CSS standard), the multiplier is approximately 3.7795. Swap in your target DPI for canvas or export workflows.
= 37.7953 px
= 59.0551 px
= 118.1102 px
MM to PX for JavaScript Conversion Chart
JavaScript conversion values at common resolutions. Use 96 PPI for CSS pixel calculations and 300 PPI for print-resolution canvas work.
| mm | 72 PPI | 96 PPI | 150 PPI | 300 PPI |
|---|---|---|---|---|
| 1 mm | 2.8346 | 3.7795 | 5.9055 | 11.8110 |
| 2 mm | 5.6693 | 7.5591 | 11.8110 | 23.6220 |
| 5 mm | 14.1732 | 18.8976 | 29.5276 | 59.0551 |
| 10 mm | 28.3465 | 37.7953 | 59.0551 | 118.1102 |
| 15 mm | 42.5197 | 56.6929 | 88.5827 | 177.1654 |
| 20 mm | 56.6929 | 75.5906 | 118.1102 | 236.2205 |
| 25 mm | 70.8661 | 94.4882 | 147.6378 | 295.2756 |
| 50 mm | 141.7323 | 188.9764 | 295.2756 | 590.5512 |
| 100 mm | 283.4646 | 377.9528 | 590.5512 | 1181.1024 |