what is em and rem? code example

Example 1: rem vs em

em -> is relative to the font-size of its direct or nearest parent 
rem -> is relative to the html (root) font-size

Example 2: rem vs em

/* rem */
Translation of rem units to pixel value is determined by the font size
of the html element. This font size is influenced by inheritance from 
the browser font size setting unless explicitly overridden with a unit 
not subject to inheritance (px or vw). 

/* em */
Translation of em units to pixel values is determined by the font size 
of the element they’re used on. This font size is influenced by 
inheritance from parent elements unless explicitly overridden with 
a unit not subject to inheritance. ---> change the menu’s font size the
spacing (paddings etc) around the menu items will scale proportionately,
independently of the rest of the layout.

Tags:

Misc Example