<length> CSS data type denotes distance measurements. It is a
immediately followed by a length unit (
mm, ...). Like for any CSS dimension, there is no space between the unit literal and the number.
For some properties, using negative lengths is a syntax error, but for some properties, negative lengths are allowed. Note also that some CSS properties accepted
<length> values also accepts
values; though also CSS dimensions, these are not
Values of the
<length> CSS data type can be interpolated in order to allow animations. In that case they are interpolated as real, floating-point, numbers.  The interpolation happens on the calculated value. The speed of the interpolation is determined by the timing function associated with the animation.
Relative length units
- This unit represents the calculated
font-sizeof the element. If used on the
font-sizeproperty itself, it represents the inherited font-size of the element.
- This unit represents the x-height of the element's
font. On fonts with the 'x' letter, this is generally the height of lowercase letters in the font;
1ex ≈ 0.5emin many fonts.
- This unit represents the width, or more precisely the advance measure, of the glyph '0' (zero, the Unicode character U+0030) in the element's
- This unit represents the
font-sizeof the root element (e.g. the font-size of the
<html>element). When used on the
font-sizeon this root element, it represents its initial value.This unit is practical in creating perfectly scalable layout. If not supported by the targeted browsers, such layout can be achieved using the em unit, though this is slightly more complex.
- 1/100th of the height of the viewport.
- 1/100th of the width of the viewport.
- 1/100th of the minimum value between the height and the width of the viewport.
Absolute length units
Absolute length units represents a physical measurement and when the physical properties of the output medium are known, such as for print layout. This is done by anchored one of the unit to a physical unit and to defined the other relatively to it. The anchor is done differently for low-resolution devices, like screens, and high-resolution devices, like printers.
For low-dpi devices, the unit px represents the physical reference pixel and the others are defined relative to it. Thus,
1in is defined as
96px which equals
72pt. The consequence of this definition is that on such devices, length described in inches (
in), centimeters (
cm), millimeters (
mm) doesn't necessary match the length of the physical unit with the same name.
For high-dpi devices, inches (
in), centimeters (
cm), millimeters (
mm) are defined as their physical counterparts. Therefore the px unit is defined relative to them (1/96 of 1 inch).
- Relative to the viewing device.
For screen display, typically one device pixel (dot) of the display.
For printers and very high resolution screens one CSS pixel implies multiple device pixels, so that the number of pixel per inch stays around 96.
- One millimeter.
- One centimeter (10 millimeters).
- One inch (2.54 centimeters).
- One point (which is 1/72 of an inch).
- One pica (which is 12 points).
- An experimental unit which attempts to render at exactly one millimeter regardless of the size or resolution of the display. This is rarely actually what you want, but may be useful in particular for mobile devices.
CSS units and dots-per-inch
Prior to Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1) , Gecko attempted (often incorrectly) to actually compute the real size to render for these, even though most other rendering engines assumed 96 DPI. Now Gecko is consistent with the other browsers.
Starting in Gecko 2.0, changes to how CSS units translate to dots-per-inch (DPI) have been made to become consistent with the behavior of other popular browsers including Safari, Internet Explorer, and Google Chrome.
Some specific examples:
- 1in is now always 96px
- 3pt is now always 4px
- 25.4mm is now always 96px
In addition, Gecko has improved ability to correctly scale absolute lengths to the actual resolution of the rendering medium, whether that's the screen or paper.
|CSS Values and Units Level 3||Working Draft||Added |
|CSS Level 2 (Revision 1)||Recommendation|| |
|CSS Level 1||Recommendation|
|Feature||Chrome||Firefox (Gecko)||Internet Explorer||Opera||Safari (WebKit)|
|Basic support||1||1.0 (1.0)||3.0 ||3.5||1.0 (85)|
|ch||no||1.0 (width of 'M') [*] |
|rem||1 (528) ||3.6 (1.9.2)||9 ||11.6 ||5.0 (533.17.8)|
|vh, vw, vm||no ||no ||9 ||no||no |
|Feature||Android||Firefox Mobile (Gecko)||IE Phone||Opera Mobile||Safari Mobile|
|vh, vw, vm||no||no||?||no||no|