Home / Companies / LogRocket / Blog / Post Details
Content Deep Dive

Using em vs. rem in CSS

Blog post from LogRocket

Post Details
Company
Date Published
Author
Lawrence Eagles
Word Count
2,266
Language
-
Hacker News Points
-
Summary

CSS units em and rem are scalable, relative length units that enhance web design's flexibility and responsiveness by allowing elements to scale based on parent or root element font sizes. Em is relative to the font size of the nearest parent element, offering precise control over modular scaling, while rem is based on the root or html element's font size, providing consistent and predictable scaling across the page. Both units support web accessibility by enabling dynamic scaling, unlike fixed units like pixels (px). Although em can lead to compounding issues when nested, rem maintains simplicity and predictability, making it popular in CSS libraries such as Bootstrap and Tailwind CSS. The choice between em and rem depends on the desired control level, with rem favored for uniform scaling and em for detailed modular adjustments.