Each resolves against a different reference:
em: the computedfont-sizeof the element it's used on. Insidefont-size(and otherfont-*properties), it uses the parent's font size, sofont-size: 1.2emmultiplies at every level of nesting.rem: the root element's computedfont-size. On the root itself it uses the initial value, which is the user's default font size (16 px unless they changed it).%: each property defines its own reference.width, all four margins and all four paddings use the containing block's width (inline size), evenpadding-top.heightuses the containing block's height, but only if that's definite; otherwise it behaves asauto.font-sizeuses the parent's font size;line-heightthe element's own.ch: the advance width of the "0" glyph in the element's font (or0.5emif it can't be measured). It approximates a character count, exact only in monospace fonts.lh/rlh: the computedline-heightof the element or root, for vertical rhythm.
Choosing:
remfor type scale and layout spacing. It follows the user's default font size, whichpxignores.emfor things that should grow with local text: button padding, icon size, gap next to a label.%(orfr, flex) for sizes relative to the container.chfor line length (max-width: 65ch) and inputs sized to their content (width: 6ch).
In media queries, em and rem use the initial font size instead, since no element is involved.