This is more of a 'philosophy' argument, but I'd like to know what the recommended practice here. I'm not setting it up as a Wiki yet in case there is an 'official' answer.
Obviously, there is no difference between 0px and 0em or whatever, so one could simply specify 0 and the units are redundant (see CSS difference between 0 and 0em). Some of the folks who answered that question argued that one should always omit the units.
However, it seems to me that omitting the unit is more error-prone, since a later change may accidentally omit the unit. It is also less consistent with non-zero elements elsewhere in the document.
In the case of zero, in the mathematics of integer numbers or real numbers or any mathematical frame, no units are necessary. Mathematically the number zero is completely defined.
There's no real right or wrong, but as a rule of thumb: For anything you want a certain, fixed size, use PX. For anything you want to scale with font-size, use EM. For anything you want to scale to the available space in the window/container, use %
0 and 0em are the same, but any value other than 0 for x and xem are not the same. Follow this answer to receive notifications.
I argue you should also omit the units.
From a programmer's perspective, 0 == null == none == false
, where 0px == 0px
only.
Which means that if you specify a border width of 0
then no border will be there, but if you specify a 0px
border, then a border of 0 px will be created (that's the idea behind it, in reality 0px
gives the exact same result like 0
).
0
makes it easier to read as it is easily distinguishable from normal unit'ed values.Conclusion: Omit the units in 0. They're not needed and confusing.
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