W3C home > Mailing lists > Public > www-style@w3.org > July 2008

Re: Clarify length units in CSS

From: Bert Bos <bert@w3.org>
Date: Fri, 25 Jul 2008 16:55:13 +0200
Message-ID: <4889E951.3080401@w3.org>
To: "www-style@w3.org" <www-style@w3.org>

Tomas Carnecky wrote:
> 
> Grant, Melinda wrote:
>>  
>> Dave said:
>>> > The problem is with the pt unit.  Web pages use the pt unit without 
>> understanding that it is supposed to be an absolute unit.  They 
>> intermix it with pixel units >> and then the Web site's design breaks 
>> if you ever change that ratio.
>>  
>> My impression is that the misunderstanding is with the px unit, that 
>> *it* is treated as an absolute measure.
> 
> There are really two questions:
> 
> 1) Should UAs try to match absolute units to the real physical lengths?
>    (Gecko does; WebKit doesn't)

Within the constraints of the device, yes. An 'in' is intended to be an 
inch and a 'pt' a point. My experience is that printers nowadays are 
quite accurate. Screens are often a few percent off in the size they 
report, but an 'in' that is only half an inch long is clearly wrong.

> 
> 2) Should CSS pixels be treated as absolute or relative?
>    (WebKit hardcodes 1in==96px; Gecko tries to follow the spec, making
>     CSS pixels relative, within some restrictions)

The 'px' unit is meant to provide a size that is small, yet visible, and 
that is reliably displayed, in the sense that you can make a 1px wide 
rule and a 2px wide rule and the second is visibly twice as thick. In 
addition, it was meant to be very easy to implement for browsers in the 
last century, because we wanted browsers to adopt CSS as quickly as 
possible. We also wanted an easy upgrade path for designers who were 
used to working in pixels when it was clear that there would soon be 
very little uniformity in the size of pixels on different devices. Hence 
we settled on a px that was the size of a device pixel of common 
computer screens at the time, but that was nevertheless "safe" for other 
(and future) devices.

Printers are so good nowadays, that they can take almost any size and 
print it sharply (as far as the unaided human eye can make out). So if 
Melinda says that 1/96 inch looks more natural than 1/128 inch, then 
that is fine as far as I'm concerned: Melinda's printers can print 1px 
and 2px wide lines at 1/96 inch with no problem.

But if you put a 200 dpi screen on your desk and the px is displayed as 
one device pixel (1/200 inch), then that is clearly too small, unless 
you're in the habit of reading with your nose against the screen.

There is no relation between 'in' and 'px' in CSS. Designers who assume 
that 1in is close to (or exactly) 96px may encounter some surprises. On 
a printer or a desktop screen, an 'in' is indeed about a hundred times 
bigger than a 'px', but on a mobile phone there can easily be twice as 
many 'px' to an 'in'; and on some 'projection' media, '1px' may well 
turn out to be bigger than '1in'.

Absolute units were basically added for printing. That's where they are 
most useful. But there may be reasons to use them on a screen as well.



Bert
-- 
   Bert Bos                                ( W 3 C ) http://www.w3.org/
   http://www.w3.org/people/bos                               W3C/ERCIM
   bert@w3.org                             2004 Rt des Lucioles / BP 93
   +33 (0)4 92 38 76 92            06902 Sophia Antipolis Cedex, France
Received on Friday, 25 July 2008 14:56:05 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 27 April 2009 13:55:10 GMT