em vs rem in CSS

In CSS, em and rem represent relative units that display the scalable and responsive results.

  • em: It is relative to the font size of the parent. For example, if a parent font size is 20px, then 2em will equal 40px.
  • rem: It’s relative to root element font size, usually <html>. For example, if root font size is 16px, then 1rem equals 16px.