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.
I say omit the unit, this will help when you compress the CSS and increase performance. It isn't much, but every little bit helps.
I always omit as it seems easier to read, the zero pops out and is easily distinguishable from the with-unit values around it.
Css specifications says that
0<unit>
can be written0
. And I've read many times that it is suggested to omit the unit, I can't remember where.So omit them.
See http://www.w3.org/TR/CSS2/syndata.html#length-units
I also like to put units by my zeros because ...
In current browsers developer tools you can easily tweak the values live with the up/down cursor keys, but if you specify
0
without a unit, then it will not work, as the browser will not know what unit do you prefer, and setting1
,2
... without a unit has no meaning.That is why I am always specifying the unit nowadays on zero values too. Any CSS minifier will change that to
0
on minification so you don't even need to care about it.I argue you should also omit the units.
From a programmer's perspective,
0 == null == none == false
, where0px == 0px
only.Which means that if you specify a border width of
0
then no border will be there, but if you specify a0px
border, then a border of 0 px will be created (that's the idea behind it, in reality0px
gives the exact same result like0
).Further Points
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.