Use relative units (em or rem) for font-size and px for the rest (opinionated).
The most used are em and rem. Usually you should prefer rem.
rem value is based on the root element's font-size. It usually refers to the html element.
For example, if the html element has a font-size of 1px, and has a div child with the width set as 2em. It’s width would be 2 * 1px: 2px.
em value is based on the parent element's font-size.
For example, if an element has a font-size of 1px, and has a div child with the width set as 2em. It’s width would be 2 * 1px: 2px.
Just use px if in need of absolute units for web.
vh and vw relate to the size of the viewport.
1vh = 1% of the viewport height
It can be used with calc() to have a size that change with the viewport at
a more moderate speed:
h1 {
font-size: calc(16px + 1vw);
}
h2 {
font-size: calc(1.2em + 3vw);
}