What is the difference between em, rem, %, and px in CSS?
Answer
px
: Absolute unit (e.g., 16px).em
: Relative to the font size of the parent element.rem
: Relative to the root element's font size.%
: Relative to the parent element's dimensions.
div {
font-size: 1.5em; /* Relative to parent */
}