CSS Units

Absolute and Relative Units

UnitRelative toTypical use
pxnothing (fixed)borders, shadows, small details
%the parentwidths in fluid layouts
emthe element's font sizepadding that scales with text
remthe root (html) font sizefont sizes and spacing (recommended)
vw / vh1% of viewport width / heightfull-screen sections, fluid type
chwidth of the "0" characterreadable line length: max-width: 65ch

Example

Example

<!DOCTYPE html>
<html>
<head>
  <title>Page Title</title>
  <style>
    html { font-size: 16px; }
    .rem { font-size: 1.25rem; }               /* 20px */
    .em  { font-size: 20px; padding: 1em; background: #f1f1f1; }  /* padding 20px */
    .vw  { font-size: 5vw; color: #04AA6D; }   /* changes with the window width */
  </style>
</head>
<body>

<p class="rem">1.25rem text</p>
<p class="em">Padding of 1em = this element's font size</p>
<p class="vw">5vw text</p>

</body>
</html>

Result