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
- cm - centimeters
- mm - millimeters
- in - inches (1 in = 96 px = 2.54 cm)
- px - pixels (1 px = 1/96th of 1 in)
- pt - points (1 pt = 1/72 of 1 in)
- 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
- em - Relative to the font-size of the element.
- ex - Relative to the x-height of the current font.
- ch - Relative to width of the '0' (zero).
- rem - Relative to font-size of the root element.
- vw - Relative to 1% of the width of the viewport.
- vh - Relative to 1% of the height of the viewport.
- vmin - Relative to 1% of viewport's smaller dimension.
- vmax - Relative to 1% of viewport's larger dimension.
- % - Relative to the parent element.