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
Status: RESOLVED INVALID
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
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-05-25 10:12 UTC by Markus Rauth
Modified: 2012-05-25 17:07 UTC (History)
2 users (show)

See Also:


Attachments

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

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

<html>

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

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

</html>


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.