demosthenes.info

I’m Dudley Storey, the author of Pro CSS3 Animation. This is my blog, where I talk about web design and development with , and . To receive more information, including news, updates, and tips, you should follow me on Twitter.

featured articles

popular favourites

Ruler

CSS Measurement Units

CSS has two forms of measurement, absolute and relative.

Absolute Relative
CSS Unit CSS Abbreviation CSS Unit CSS Abbreviation
PixelspxPercent%
PointsptEmem
InchesinExex
CentimeterscmRoot emrem
PicaspcViewport widthvw
Viewport heightvh
Viewport minimumvm
characterch
Gridgd

rem, vh, vw are CSS3 measurement units, supported by modern browsers.

1em is the width of the m character in the default font set for that browser. (ex is the height of the x character in a font). rem allows you to set a root font size for size for the entire page, with sizes for elements relative to this measurement:

  1. html { font-size: 62.5%; }
  2. body { font-size: 1.4rem; }
  3. h1 { font-size: 2.4rem; }

(The measurements above are used because they map exactly to pixels: with a base font-size of 62.5% for a page, the body size maps to 14 pixels, and h1 to 24 pixels.)

The viewport is the browser window: vh, vw and vm can scale elements to its current size. This could be used to restrict the upper scaled size of images, for example:

  1. img { max-width: 90%vw; }

ch is the equivalent of em, but applied to the width 0 numeral of the chosen font.

gd relates to the CSS3 grid; unfortunately, no browser yet supports the grid module.

You never need to specify units when declaring a value of 0: zero centimeters is the same as 0 pixels. In all other cases, units of measurement should be declared 2em, 2px, etc, not 2.

With the exception of pixels, all systems of measurement can take floating point values: 2.25em, 5.3cm, etc.

Generally speaking, CSS written for screen display devices should use relative units (percent, em and ex), with few exceptions (such as bitmapped images and elements that refer to bitmapped images).

You must be signed up in order to leave comments.

Better to have rich user experience, it is recommended to use the relative unit length. Because, the user can view the web pages from various devices.

If the physical properties of the output devices (monitor, printer etc) are known, then it is advisable to use the absolute length units.

CSS Training

posted by gym prathap

web developer guide

featured comment

by Aisling Brock in New Business Card Design

what i'm reading

A Feast for Crows: A Song of Ice and Fire: Book Four
A Feast for Crows: A Song of Ice and Fire: Book Four

what i'm watching

Prometheus: Collector's Edition (Bilingual) [Blu-ray 3D + Blu-ray + DVD + Digital Copy]
Prometheus: Collector's Edition (Bilingual) [Blu-ray 3D + Blu-ray + DVD + Digital Copy]

what i'm playing

Borderlands
Borderlands

what i'm hearing

Planets
Planets

blogs

podcasts

no ads ever

This blog is free of advertising, and always will be.

creative commons licensed

The content of this blog is free to use in whatever way you wish under the Creative Commons license.