CSS units control size, spacing, and layout behavior. They fall into two categories. Absolute Units px (pixels) — fixed size, does not scale with user preferences. Best for borders, shadows, and fine-detail sizing. Avoid for font sizes and layout widths. Relative Units (Recommended for Responsive Design) em — relative to the parent's font size (1.5em = 1.5x parent). rem — relative to the root (html) font size (consistent, predictable — preferred for font sizes). % — relative to the parent element's size (great for widths). vw/vh — relative to the viewport width/height (100vw = full viewport width). fr — fractional unit used exclusively in CSS Grid to distribute available space. CSS Math Functions CSS Math Functions allow dynamic calculations directly in stylesheets: calc() performs…
Key Takeaways
px for borders/details; rem for font sizes; % for widths.
rem is relative to root font size — predictable and consistent.
vw/vh are relative to viewport; fr is for Grid tracks.
calc() does arithmetic: calc(100% - 40px).
clamp(min, preferred, max) is ideal for fluid responsive values.