www.fgks.org   »   [go: up one dir, main page]

CSS Length Units Reference

This section defines the supported length units for Cascading Style Sheets (CSS) text, layout, and positioning properties. Unless otherwise specified, the length units are supported as of Microsoft Internet Explorer 3.0 or later.

CSS Length Unit Table

Measurements and positions in CSS properties are indicated in length units. Windows Internet Explorer supports two types of length units: relative and absolute.

  • Relative—specifies a length in relation to another property. Relative length units scale better from one output device to another (such as from a monitor to a printer) and in comparison to other page elements.
  • Absolute—an exact measurement, such as inches or centimeters. Absolute length units are useful when the physical properties of the output device are known.
Relative length units
em The computed font-size.
ex The height of a lowercase "x".
pxPixels, relative to the viewing device.
%Percentage.
Absolute length units
inInches (1 inch = 2.54 centimeters).
cmCentimeters.
mmMillimeters.
ptPoints (1 point = 1/72 inches).
pcPicas (1 pica = 12 points).

The 'em' unit is relative to the computed value of the font-size attribute of the element. When 'em' occurs in the value of font-size itself, it refers to the font size of the parent element. It can be used in both vertical and horizontal measurements.

Pixel units are relative to the resolution of the viewing device; for example, a 600 dots per inch (dpi) laser printer requires more dots to acheive the same pixel density as a computer monitor.

Percentage values are always relative to another value, for example a length. Attributes that allow percentages will also define the property to which the percentage refers. For example, the width of a table cell can be specified as a percentage of the entire table.

Standards Compliance

According to CSS, Level 1 (CSS1), length values must specify a unit type identifier. Earlier versions of Internet Explorer permit you to use certain invalid declarations and treat numbers without any unit type identifier as pixel (px) units. When you use the !DOCTYPE declaration to specify standards-compliant mode, Internet Explorer 6 and later ignore style sheet declarations that do not comply with CSS 1.

Related Topics



MSDN Library
Web Development
HTML and CSS
Cascading Style Sheets (CSS)
CSS Reference
CSS Length Units Reference