This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 17182 - DIV width in cm has an incorrect length
Summary: DIV width in cm has an incorrect length
Alias: None
Product: CSS
Classification: Unclassified
Component: Values and Units (show other bugs)
Version: unspecified
Hardware: PC Linux
: P2 normal
Target Milestone: ---
Assignee: Tab Atkins Jr.
QA Contact: public-css-bugzilla
Depends on:
Reported: 2012-05-25 10:12 UTC by Markus Rauth
Modified: 2012-05-25 17:07 UTC (History)
2 users (show)

See Also:


Description Markus Rauth 2012-05-25 10:12:37 UTC

this code should displays a div with length of 6cm.


    <title>Test of width declaration at a DIV</title>

    <div style="background-color: #000; width: 6cm;">Test</div>


But if I measure it is 5.7cm.

The same is if I declare a div with 2cm, than I got 1.9cm.

Is this a Bug?
Comment 1 Tab Atkins Jr. 2012-05-25 17:07:49 UTC
I assume you mean that you measured it with a physical ruler against your screen?

No, this is not a bug.  Web compatibility requires us to fix the ratio between the 'px' and the 'pt' unit.  Points, though, are defined in terms of inches, so we had to fix the ratio of 'px' to 'in' as well.  Obviously, then, the ratio of 'px' to 'cm' and 'mm' is similarly fixed now.

So, all the physical units are worth a constant and unchanging number of 'px' units.  We now have two options.  First, we could make the physical units correct.  However, this would mean that '1px' will usually not be an integer number of device pixels, which makes rendering *very* slow and somewhat unpredictable/fuzzy.  Second, we could make the 'px' unit be an integer number of device pixels.  However, this would mean that the physical units in CSS aren't quite correct on all screens - in the worst case (a 144dpi screen) they'll be 50% off from "real" units.  However, the problem is much smaller on most screens, and gets better as screens get higher resolution.

The second option was judged to be much less troublesome for the web.  So, using physical units like "6cm" will often produce lengths on the screen that aren't *quite* 6 centimeters.