How the px → em → rem conversion works
px are absolute (device pixels), while em and rem are relative. Responsive web design prefers relative units because they scale with user settings and container font-sizes.
Formulas
em = px ÷ contextFontSize
rem = px ÷ rootFontSize
If you know em and want px: px = em × contextFontSize
em vs rem
em is relative to the current element’s font-size and compounds (nested elements can multiply the effect). rem is relative to the root HTML font-size and stays consistent throughout the document.
FAQ
1. Which unit should I use for padding/margin?
Use em if you want spacing to scale with the element’s text; use rem for consistent spacing across components.
2. My design is in Figma in px — what do I enter?
Enter the exact px from the design, then input the real font-size used in that component. The converter will output em/rem you can paste into your CSS.
3. Why is my number not round?
Because not all px values divide evenly by your chosen font-size. You can round to 3–4 decimals; browsers handle that fine.