What is the difference between em and rem units ?

sanju saini
Feb 2, 2021

--

Both em and rem units are based on the font-size CSS property. The only difference is where they inherit their values from.

  • em units inherit their value from the font-size of the parent element
  • rem units inherit their value from the font-size of the root element (html)

In most browsers, the font-size of the root element is set to 16px by default.

--

--

sanju saini
sanju saini

Written by sanju saini

Senior Software Engineer with 4.5+ years of experience in full-stack development, specializing in Python, Golang, PHP, Django, FastAPI, React, and RESTful APIs.

No responses yet