Units in CSS

Absolute

  • Absolute length units are fixed and length will appear as exactly that size.
  • Absolute length units are not recommended for use on screen, because screen sizes vary so much.


Absolute Units

  1. cm - centimeters
  2. mm - millimeters
  3. in - inches (1 in = 96 px = 2.54 cm)
  4. px - pixels (1 px = 1/96th of 1 in)
  5. pt - points (1 pt = 1/72 of 1 in)
  6. pc - picas (1 pc = 12 pt)


Relative

  • Relative length units specify a length relative to another length property.
  • Relative length units scales better between different rendering mediums.


Relative Units

  1. em - Relative to the font-size of the element.
  2. ex - Relative to the x-height of the current font.
  3. ch - Relative to width of the '0' (zero).
  4. rem - Relative to font-size of the root element.
  5. vw - Relative to 1% of the width of the viewport.
  6. vh - Relative to 1% of the height of the viewport.
  7. vmin - Relative to 1% of viewport's smaller dimension.
  8. vmax - Relative to 1% of viewport's larger dimension.
  9. % - Relative to the parent element.