When it comes to units of measurement such as pixels px
, points pt
, they are often seen as absolute units. Pixels are particularly useful when you want an element to maintain a consistent size and not be resized, making them ideal for icons, certain images, or layout decorations.
On the other hand, relative units like em
, rem
, %
, vw
, vh
are more suitable for responsive design. Relative units are calculated based on base sizes. For example, em
is based on the parent element while rem
is based on the root element. These relative units work well for font sizing, adjusting according to the user's preferences unlike fixed pixel sizes.
Percentages %
are commonly used in layouts where elements are sized in percentage columns that adjust with screen size changes. By using media queries, these column percentages can be further adjusted based on different screen sizes.
In my opinion, viewport width vw
and viewport height vh
may be less common but can be handy when designing elements based on the actual viewport size. For instance, creating backgrounds with multiple colors or layers could be one creative use case for these units.