Units in CSS

Absolute

Fixed values cm, mm, px.

Pixels used to cause a lot of problems, as they were a fixed unit (one dot on the screen). Now, it follows the reference pixel. So not a dot on screen anymore.

<aside> ⚠️ We use calc function to do different kind of calculations in css. A better alternative can be clamp function which takes 3 values the middle value is the same as what you pass to calc(), the opening value specifies the minimum size and the closing value specifies the maximum size.

</aside>

Relative

Depends on other things like parent etc.

Used to make the website responsive.

Units are %, em, rem, vh, vw, max-height, min-height.

There are two types of relative units.

Percentages are mainly used for widths, and are pretty easy to understand.

Some General Rule of thumb

Font-size = rem

Padding and margin = em

Widths = em or percentage