CSS - Units

CSS Units

Every property in the CSS has a specific value for the selector, the value for that property depends on the type of property. For many CSS Properties type of value needs to be defined in length unit, so the value comprising of a numeric/number value with a unit.

The numeric value can be either an integer or a real number.The units can be either relative or absolute, if the physical properties of the output medium are known then absolute unit is better option.

Relative Units in CSS

For Example
Unit Description
em the current font size
ex height of letter x of the current font
px pixels

Absolute Units in CSS

For Example
Unit Description
mm millimeters
cm centimeters
in inches
pt points (1 pt = 1/72 in)
pc picas (1 pc = 12 pt)

Percentage Units

A percentage value is formed by an optional + or -, followed by a number, followed by %. There are no spaces in a percentage value.

Percentage values are relative to other values, as defined for each property. Most often the percentage value is relative to the element's font size.