Promptles
Frontend & Responsive Design

rem vs em vs px

intermediate

Definition

Three different units for sizing things on a webpage. 'px' is a fixed measurement that never changes. 'em' is relative to the size of whatever it's nested inside. 'rem' is relative to the page's overall base size: which makes it predictable and friendly to people who change their browser's text size for readability.

In the wild

A reader with poor eyesight bumps up their browser's default text size by 50%. On a site that uses 'rem' for everything, all the text and spacing grows comfortably alongside that change. On a site that uses fixed pixels everywhere, the layout stays cramped no matter how the reader adjusts their browser.

More from Frontend & Responsive Design