How Do I Develop My Website — Part 2: EM vs REM
Is it better to use EM or REM?
EM and REM are one of the units used in the website development process. The units of measurement “em” and “rem” are two important concepts in CSS that are used to determine the size of elements in web layouts. The unit “em” refers to the size relative to the font size of the parent element, while “rem” refers to the size relative to the font size of the root element (usually the <html>
element).
By using the “em” unit, the size value of an element will depend on the font size of its parent element. For example, if the parent element’s font size is 16px, and we set the child element’s size to 2em, then the child element’s size will be 32px (2 by 16px).
In contrast, “rem” units allow for more consistent measurements because they do not depend on the element hierarchy. The element size specified in “rem” always refers to the font size of the root element. This makes it easier to set element sizes globally, without being affected by the nesting structure.
The use of “em” and “rem” provides great flexibility in layout design, especially when wanting to create good responsiveness. By understanding the differences between the two, developers can manage element sizes in a more structured and efficient manner when it comes to web layout.
It is important to choose the unit wisely according to the project requirements. The “em” and “rem” units can be used together or separately based on the specific design scenario. For example, “em” can be ideal for setting padding or margins based on font size, while “rem” can be used to set font size consistently across the page.
In modern web development, a deep understanding of the “em” and “rem” units helps create designs that are responsive, easy to maintain, and consistent across a variety of devices and layouts.
This article was first published on https://dwipayana-ismulya.my.id/posts/css-em-vs-rem/