Office of Information Technology Office of Information Technology Susquehanna University Susquehanna University Office of Information Technology

Director's OfficeTechnology Support ServicesAdvanced TechnologiesTechnical OperationsAdministrative Information Services

Style Sheet Reference: Measurement Units

[Contents] [Previous] [Next]


This section covers the commonly used units of measurement in style sheets


Relative Measurements

The actual size of these units varies as other page properties change. They scale according to the way other elements are being scaled.

Relative Measurements

Syntax Description
em The height of the element's font
ex The height of the letter "x"
px Pixels (Lower resolution = larger pixels)
% Percentage (Percentage of containing box)

It is highly recommended that you use relative units when laying out pages in CSS. Your pages will scale smoothly between many different resolutions, monitor sizes, and devices. In particular, the em unit is perhaps the most versatile and useful of all the units.

The em unit is so well-liked because it scales relative to the font size. If all the margins, padding, sizes of elements on a page are based on the font size, then all of these properties will stay in proportion as the size of the font changes.

Another unit that's relative to the font size, the ex, is based upon the height of the letter "x" of the current font. This unit is not as reliable as the em, however, because two fonts that have the same em size quite often have a different ex height.

Percentages can be substituted for definite measurements in many instances, and what they are a percentage of changes depending on the property. In most cases, the percentage refers to the size of the equivalent characteristic of the parent element. e.g. A font size of 80% means you want it to be 80% of the size of the parent element's font.

Example

P { padding: 1.5em; font-size: 1.2em; border: thin solid black }

Here is a paragraph whose padding is specified as 1.5em. This means that the padding will always be 1.5 times the height of the font contained within the paragraph, no matter what size the font happens to be.


Absolute Measurements

These units are of predefined length, and do not change according to browser size, font size, or screen resolution.

Absolute Measurements

Syntax Description
in Inches (1 inch = 2.54 centimeters)
cm Centimeters
mm Millimeters
pt Points (1 point = 1/72 inches)
pc Picas (1 pica = 12 points)

Since absolute measurements don't scale as relative units do, caution must be employed when/if using them in your webpages. Always keep in mind how elements will look when viewed in other resolutions, and try to test your layout in different browsers/resolutions before publishing it.

Example

P { font-size: 14pt; padding: 15px }

Here is a paragraph with the above style applied. The characteristics of this paragraph will not change, regardless of how other elements are resized.


[Contents] [Previous] [Next]