Type a font-size in any unit and watch the browser compute its px. What becomes of em in a nested menu, rem when the text is enlarged, vw on a phone screen?…
The wrong unit = text that ignores the user’s setting (accessibility), a menu that swells, or a title that shrinks to nothing on a phone. Knowing each unit’s base = knowing what happens before you try it.
rem from the root, em from the parent, vw from the window
px for font-size, said to hurt accessibility px ignores the text size users set in their browser. Use rem for font sizes; px for what must stay fixed, such as a 1px border.em in a nested menu or list piles up to huge Every level multiplies its parent: 1.2 → 1.44 → 1.73. Use rem when the size must match at any depth.vw alone, too small on a phone Hold it with clamp(1.5rem, 4vw, 3rem): it still flows, but has a floor and a ceiling, and its rem limits follow the user’s setting.2rem, move Mr. Sugeng’s text size off 16 The title grows with it: rem counts from the root, and the root from the user’s setting..menu li from 1.2em to 1.2rem All three levels match. em compounds through the parent, rem always goes to the root.4vw in h1, then slide the window width The title follows the window’s width, down to tiny on a phone.10px on html, then move Mr. Sugeng’s text size Every rem stops following the user: the root is locked in px.