Overview

rem resolves against the root (<html>) font size and em against the element’s own font size (for font-size itself, the parent’s). Size type and spacing in rem by default so nested components stay predictable and user font settings scale the page. Use em for padding and icon sizes that should track a component’s own text size.

Rules

  • em compounds: a 1.2em child inside a 1.2em parent renders at 1.44 times the root. That is usually the bug.
  • Set html { font-size: 100%; }, not a pixel value, so the browser default (16px) and user preferences are respected.
  • Use px for borders and shadows. Avoid it for text and spacing that should scale with the user’s font size.
html { font-size: 100%; }
h1 { font-size: 2rem; }       /* 2 x root, at any depth */
.btn { font-size: 0.875rem; padding: 0.5em 1em; } /* padding tracks the button's text */