CSS provides many units for sizing elements. Choosing the right unit is key to creating flexible, responsive layouts.
Fixed Units
px— pixels, fixed size (not relative to anything)
Relative Units
em— relative to the parent element's font sizerem— relative to the root (html) element's font size%— relative to the parent elementvw— viewport width (1vw = 1% of viewport width)vh— viewport height (1vh = 1% of viewport height)
Max/Min Sizing
min-width/max-width— clamp element widthmin-height/max-height— clamp element height
Tip: Use rem for font sizes and % or vw/vh for layout dimensions. Avoid using px for anything except borders and small fixed sizes.