Sobes.tech
Middle

What does the EM unit depend on — the nearest REM or the parent font-size?

sobes.tech AI

Answer from AI

The em unit in CSS depends on the font size of the parent element, not the nearest rem.

  • em is a relative unit that scales relative to the current font-size of the parent.
  • If the parent has font-size: 16px, then 1em in the child element will be 16px.
  • Unlike em, rem always refers to the root element (<html>), that is, its font-size.

Example:

html { font-size: 16px; }
.parent { font-size: 20px; }
.child { font-size: 1.5em; /* will be 1.5 * 20px = 30px */ }
What does the EM unit depend on — the nearest REM or… - sobes.tech