The question in the title is already fully formulated, I can only explain why it is needed. Conveniently, this is mainly when adjusting positioning when you pick up coordinates. If you change the value from zero to non-zero in the selection process, and then again to zero, you will get tired of adding, then deleting px .

  • one
    Of course, correctly. Moreover, it is sometimes necessary ... - Alexey Ten
  • one
    @AlexeyTen, when can it be necessary to specify units for the value 0? - Grundy
  • 3
    @Grundy in short for flex developer.mozilla.org/en/docs/Web/CSS/flex flex: 0flex-grow=0 , flex: 0pxflex-basis=0px . Admittedly, I only know this case. But I do not exclude that there may be somewhere else in a similar situation. - Alexey Ten
  • one
    @RomanGrinyov, with calc everything is according to the specification : it turns out that inside calc is not yet length so you cannot omit the dimension in 0 . And the developer’s tools also show that the rule is incorrect if there is no dimension - Grundy
  • one
    @RomanGrinyov, or rather, even like this: If one side is a <number> and the other is an <integer>, resolve to <number>. , that is, the output of calc is the number 100 , which is an invalid value for the margin property - Grundy

1 answer 1

As stated in the specification :

for zero lengths the unit identifier is optional


For zero values, the indication of units of measurement is optional.

Thus, it does not make any difference to indicate for the value 0 units or not.

In addition, oddly enough: 0px === 0em === 0%