DEV Community

Discussion on: Use em For Padding and Margin

Collapse
datmt profile image
Mạnh Đạt Author

It's a common practice to use rem for font size and em for padding and margin. For border, use px.

The reason (to use em for padding and margin) is as em based on font size of the element, when you change the font size, the margin and padding will reflect that change.

In the case of font size, using rem make it more predictable since it is based on the root element only, not parent's size like while using em.

Collapse
eliasmqz profile image
Anthony Marquez

Ahh that makes sense. Thank you for clarifying!

Thread Thread
datmt profile image
Mạnh Đạt Author

My pleasure. I'm glad it helps :)