In my stylesheet I use em for font sizes.
Is it bad practice to use this for padding and margin as well so that when the font scales the margin and padding will scale with it?
It totally depends on your need. Em should be avoided because it depends on the native browser settings, but if you use px then css of the page will be cross browser compatible.
Use EM where you have to make more scaling than the root font size. And use REM where you need value according to the root there you can use REM units.
em units can be used for much more than just setting font-size however, and they can be used pretty much everywhere units are expected (padding, margin, width, height, max-width,…you get the picture!) When em units are used on other properties than font-size , the value is relative to the element's own font-size .
The em is simply the font size. In an element with a 2in font, 1em thus means 2in. Expressing sizes, such as margins and paddings, in em means they are related to the font size, and if the user has a big font (e.g., on a big screen) or a small font (e.g., on a handheld device), the sizes will be in proportion.
I don't think that its a bad practice, but I don't think that most of developers will use it nowadays: some thought on it:
It totally depends on your need. Em should be avoided because it depends on the native browser settings, but if you use px then css of the page will be cross browser compatible.
Please refer to this post : Why em instead of px? This post will tell you when to use EM and when PX.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With