Reputation: 777
NB: I am not asking which style is better (opinion), but about documented benefits of using one specific style (factual), as I could not find any sources explaining the reasoning behind it. I fully understand that it is not good idea to ask opinion-based questions on StackOverflow. On this particular code-style, no factual explanation could be researched online, so I found it appropriate to ask the question here. I apologize in advance if I am still going against the meta!
The Question:
Many CSS style guidelines mention omitting leading '0's in values, but I cannot find any explanations/reasoning behind the recommendation.
font-size: .8em;
Many style guides, such as from Google, jQuery, etc. do not recommend having a leading '0' as seen above, while there are still some that do recommend having the leading '0' as below:
font-size: 0.8em;
As per the latter style, I could see that its benefits may be prevent reading error (.8
being mistakenly read as 8
, for example).
I would love to hear some explanations/opinion about the benefits of the former style, as I could not come up with an explanation myself, or find anything upon hours of searching. There has to be reasons why many style guides point this out, but I seem to be blind.
Upvotes: 5
Views: 2151
Reputation: 10547
There an easy answer as to why one might omit a leading zero for technical reasons. Understanding at the scale Google does thing each extra byte across the wire can have actual, meaningful impact on bottom line and possibly on the experience of my end users. This would led me to remove unneeded characters. You don't even need to be Google scale for this to start to add up.
I would be more apt to require the leading zero for clarity of reading in source and remove it via tooling for production assets. If you are using tools for CSS ugilification, then I can see no technical reason for requiring or omitting the leading zero. It is just a stylistic choice.
Upvotes: 4